LuaLS / LuaLS/lua-language-server
Exact classes can have fields injected when used as parameters to funcitons
未关闭
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
在 lua-language-server 中复现提供的 Lua 代码片段,并检查函数参数类型检查对 exact-class 的处理。当向 TestClass 传入额外的 d 字段时产生所请求的 inject-field 诊断,同时已声明的 a、b 和 c 字段仍被接受,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 42/100