LuaLS / LuaLS/lua-language-server
Do not shadow/re-inject fields in child-classes
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?
Diagnostics/Syntax Checking
Expected Behaviour
When assigning to a field which is already defined in one of it's supers, no injection should be used.
Actual Behaviour
Assigning to existing field is not possible as I effectively end up with two fields A.test and B.test.
The only valid workaround I know would be using setters in A.
Just disabling (exact) does not solve the issue, just disable the warning.
Reproduction steps
---@class (exact) A
---@field test number
local a = {}
function a:init()
--This is fine
self.test = 0
end
---@class (exact) B : A
local b = {}
function b:init()
--This is an injection and thus invalid
self.test = 0
end
Additional Notes
If shadowing a field is explicitly wanted, one can still define/type explicitly. But I think by default, no additional field should get injected.
Issue is a bit related to @override (#2569).
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 reproduction in the issue and trace the diagnostics/type-checking path for assignments to fields inherited through B : A. The fix is done when self.test = 0 in B:init() does not inject a second field for the inherited A.test, while explicitly requested shadowing remains possible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100