LuaLS / LuaLS/lua-language-server
Lua Language Server Fails to Infer Type When Passing Multiple Return Values to Generic Function
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?
NeoVim
Which OS are you using?
MacOS
What is the issue affecting?
Type Checking
Expected Behaviour
---@return integer
---@return string
local f = function()
return 1, "a"
end
---@generic T
---@generic U
---@param t T
---@param u U
---@return U
local g = function(t, u)
return u
end
local x = g(f())
When the function g is called with the multiple return values of f, the Lua Language Server should infer the type of x based on the second return value of f (string), corresponding to the second generic type parameter (U) in g.
Actual Behaviour
The Lua Language Server fails to infer the type of x. Instead, the type is left unknown.
Reproduction steps
- Write the following Lua code in an editor with the Lua Language Server enabled:
---@return integer
---@return string
local f = function()
return 1, "a"
end
---@generic T
---@generic U
---@param t T
---@param u U
---@return U
local g = function(t, u)
return u
end
local x = g(f())
- Observe the type inference for x.
- Note that the type of x is not inferred as string as expected.
Additional Notes
No response
Log File
No response
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 reproduzindo o snippet de Lua no NeoVim com o Lua Language Server habilitado e inspecione o caminho de inferência de tipos genéricos para chamadas que recebem múltiplos valores de retorno. Considera-se concluído quando a variável x for inferida como string, correspondendo ao segundo valor de retorno de f e ao parâmetro genérico U.
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
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 38/100