LuaLS / LuaLS/lua-language-server
Exact classes can have fields injected when used as parameters to funcitons
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
Love the new exact class! When using it though, I noticed that I could still 'inject' fields into an exact class when it is used as the input to a function. Example:
```
---@class (exact) TestClass
---@field public a number
---@field public b string
---@field public c boolean
---@param test_param TestClass
local function test(test_param)
end
test({a = 1, b = "2", c = true, d = 4})
```
causes no error.
I am not sure if this is intended or not, but I would expect to get an warning like: ```Fields cannot be injected into the reference of `TestClass` for `d`. To do so, use `---@class` for `test_param`.Lua Diagnostics.(inject-field)``` here.
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
Reproduce the provided Lua snippet in lua-language-server and inspect the exact-class handling for function parameter type checking. Done when passing an extra d field to TestClass produces the requested inject-field diagnostic, while the declared a, b, and c fields remain accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100