LuaLS / LuaLS/lua-language-server
string.unpack vararg returns
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?
Annotations, Type Checking, Completion
Expected Behaviour
The current string.unpack annotations (for the returns) are as following:
---@param fmt string
---@param s string
---@param pos? integer
---@return any ...
---@return integer offset
---@nodiscard
function string.unpack(fmt, s, pos) end
The function will indeed return any number of any returns followed by a single integer return for the new offset. As such you would expect that in the following example code, all of the returns are any except the last return be integer:
local a, b, c, d, offset = string.unpack('I2I2I2I2', "some binary data")
Actual Behaviour
Instead of the a, b, c, d being typed as any and offset being typed as integer, we instead see that a is typed as any, b is typed as integer, and c, d, offset are typed as nil.
This happen because it is not supported for a function to return a vararg followed by any return; it is always that vararg returns are the last return. Because of that, only the first return is typed as any and from there the second @return takes.
Reproduction steps
- Copy the example code.
- Hover over each return variable to notice the type.
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 com a anotação de string.unpack e reproduza o problema na extensão do Visual Studio Code passando o cursor sobre cada variável retornada. Rastreie como o verificador de tipos trata um vararg seguido pelo retorno do offset. Está concluído quando os valores de unpack são tipados como any e o offset final é tipado como integer.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- lua
- Domínio
- tooling
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100