LuaLS / LuaLS/lua-language-server
Question mark optional syntax not supported in fun() declarations
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?
Windows
What is the issue affecting?
Type Checking
Expected Behaviour
Optional value to actually be optional
Actual Behaviour
It's not optional.
This code block should show as Human? and throw warnings for not checking nil. If I manually annotate with ---@param man Human? this works as expected.
The class in question:
---@class Command
---@field info string What the command does.
---@field usage string? How to use the command.
---@field alias string[]? Aliases of the command.
---@field canCall (fun(player: Player): boolean)? Function which checks whether a player can call this command.
---@field call fun(player: Player, human: Human?, args: string[]) Calls the command.
---@field autoComplete fun(args: string[])? Function which manipulates arguments when pressing tab in the terminal.
---@field cooldownTime number? How many seconds a player has to wait before using the command again.
I have also tried with human?: Human and human?: Human? but neither way works.
Reproduction steps
- Create class with a field with a short form function declaration with an optional value parameter
- Attempt to create object of class with that field,
- Parameter correctly types, except as not optional.
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 exemplo de campo de classe na extensão do Visual Studio Code, concentrando-se na declaração de função abreviada com um parâmetro Human nullable. Compare-o com o caso anotado manualmente ---@param man Human?; está concluído quando o parâmetro é inferido como opcional e os avisos de verificação de nil aparecem conforme descrito.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- lua, vscode
- Domínio
- devtools
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100