LuaLS / LuaLS/lua-language-server
Better support for varargs in functions in classes declared with @field
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
I ran into a minor problem with how vararg is handled in function declarations in an field annotation when the function declaration itself later explicitly lists the arguments.
```
---@class Handler
---@field ReceiveMsg fun(self: Handler, type: number, ...: string)
local handler = {}
function handler:ReceiveMsg(arg1, arg2, arg3, arg4)
--- arg2 is inferred as string, but arg3 and arg4 are "any"
end
```
Why do I even have this mismatch between field and function declaration? The field annotation comes from a library and is an event handler -- the number of parameters depend on a lot of things, but for a given implementation you usually only care about a few that you explicitly declare.
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 issue's Handler example with an @field ReceiveMsg vararg annotation and an explicit method declaration. Trace the vararg type propagation during function declaration and parameter inference. Done means arg2, arg3, and arg4 are inferred consistently as string rather than leaving later arguments as any.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100