LuaLS / LuaLS/lua-language-server
Question mark optional syntax not supported in fun() declarations
Personne n'a encore pris cette issue.
- Langage dominant
- Lua
- Étoiles
- 4.4k
- Forks
- 442
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
### 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:
```lua
---@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
1. Create class with a field with a short form function declaration with an optional value parameter
2. Attempt to create object of class with that field,
3. Parameter correctly types, except as not optional.
### Additional Notes
_No response_
### Log File
_No response_
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire l’exemple de champ de classe dans la Visual Studio Code extension, en vous concentrant sur la déclaration de fonction abrégée avec un paramètre Human nullable. Comparez-le au cas annoté manuellement `---@param man Human?` ; c’est terminé lorsque le paramètre est inféré comme optionnel et que les avertissements de vérification de nil apparaissent comme décrit.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- lua, vscode
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100