LuaLS / LuaLS/lua-language-server

Better support for varargs in functions in classes declared with @field

Open
#2,556 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.