LuaLS / LuaLS/lua-language-server
Do not shadow/re-inject fields in child-classes
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的 Lua 复现开始,跟踪通过 B : A 继承的字段的赋值所经过的诊断/类型检查路径。当 B:init() 中的 self.test = 0 不再为继承的 A.test 注入第二个字段,同时仍可进行显式请求的遮蔽时,修复就完成了。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100