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, Diagnostics/Syntax Checking
Expected Behaviour
---@class TArg
---@field x number
---@field y number
---@class Parent
---@field T TArg
---@class Child : Parent
Child = {}
function Child:init()
self.T = { y = 1, w = 1} --- Expect type warning
end
print(Child.T) -- Expect T to be TArg but got `table`
- LuaLS should warn that
{ y = 1, w = 1 } does not match TArg (since w is not defined).
Child.T should retain its inherited type (TArg), not become table.
Actual Behaviour
- LuaLS does not warn about the incorrect structure.
T in Child is now treated as unknown or table, instead of TArg.
Reproduction steps
- Paste the code snippet on any editor and check the types
Additional Notes
Possible workarounds
- Manually redeclaring
T in Child
---@class Child : Parent
---@field T TArg
This issue is particularly problematic in large projects where inheritance is heavily used. Manually re-declaring every inherited field just because it gets reassigned is redundant and error-prone.
Log File
No response
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, Diagnostics/Syntax Checking
Expected Behaviour
{ y = 1, w = 1 }does not matchTArg(sincewis not defined).Child.Tshould retain its inherited type (TArg), not become table.Actual Behaviour
Tin Child is now treated asunknownortable, instead ofTArg.Reproduction steps
Additional Notes
Possible workarounds
TinChildThis issue is particularly problematic in large projects where inheritance is heavily used. Manually re-declaring every inherited field just because it gets reassigned is redundant and error-prone.
Log File
No response