LuaLS / LuaLS/lua-language-server
Question mark optional syntax not supported in fun() declarations
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
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_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the class-field example in the Visual Studio Code extension, focusing on the short-form function declaration with a nullable Human parameter. Compare it with the manually annotated `---@param man Human?` case; done means the parameter is inferred as optional and nil-check warnings appear as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100