LuaLS / LuaLS/lua-language-server
Break in loop makes variable go out of scope early?
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Lua
- Estrelas
- 4.4k
- Forks
- 442
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
I was trying to fetch a table that could be within a number of tables. Leaving early if it was found
I wanted that locally scoped variable to be the same type after the loop as before it
Actual Behaviour
Only for my variable scoped outside the loop to be unknown after it.
In an attempt to band-aid what I originally luals choking a little, I tried casting it. Only to find it was in fact unaware it even existed.
Reproduction steps
As minimal I can get the code to be and reproduce it:
---@type {[any]:A}
local T
function F()
---@class A
local a
for _, i in pairs{} do
a = T[1]
if a then break end
end
-- See it complain the `a` variable
---@cast a A
end
Additional Notes
No response
Log File
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece com a reprodução mínima em Lua no issue e inspecione o comportamento da verificação de tipos em torno da variável local a, do loop for e de break. O trabalho estará concluído quando a mantiver seu tipo A após o loop e a linha ---@cast a A não for mais reportada como desconhecida; adicione um teste de regressão usando essa reprodução.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- lua
- Domínio
- devtools
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 50/100