LuaLS / LuaLS/lua-language-server
Table literals aren't properly checked for field injections and missing fields
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?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
I'd expect tables created in the return statement to check for missing fields, and those created outside of them to check for injected fields.
Actual Behaviour
There are no warnings emitted for the attached code.
Reproduction steps
Code to reproduce the issue:
---@class Tile
---@field name string
local Tile = {}
---@return Tile
function Tile.new()
---@type Tile
local d = {
name = 'abc',
f = 10 -- No warning when a field is being injected
}
return {
f = 10 -- No warning even though there's a missing field and a field is being injected
}
end
Note that it won't produce any warnings, regardless of configuration (as far as I can tell).
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 with the Lua type-checking path for the reproduced Tile example and inspect how table literals in return statements and typed locals are validated. Reproduce the issue in the VS Code extension, then verify that injected fields produce warnings and that the returned table reports both the missing name field and the extra f field.
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
- Mostly clear
- Newbie friendliness
- 35/100