LuaLS / LuaLS/lua-language-server
Union table|class doesn't accept a generic table and only accepts a class instance (causing false missing-fields diagnostic)
还没有人认领这个 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?
Windows
What is the issue affecting?
Type Checking, Diagnostics/Syntax Checking
Expected Behaviour
When a function is declared as accepting both table and a custom class type, it should accept getting passed a generic table.
Actual Behaviour
LLS insists on a table matching the class being passed (with all the fields set) and reports the missing-fields diagnostic when passing a generic table.
Reproduction steps
LLS definition file contains the following:
---@meta
---@class TestClass
---@field TestField number A test field in test class
TestClass = {}
-- TestFunction1
---@param generic_table_or_testclass_instance table|TestClass
function TestFunction1(generic_table_or_testclass_instance) end
-- TestFunction2
---@param generic_table table
---@param testclass_instance TestClass
---@overload fun(generic_table: table)
---@overload fun(testclass_instance: TestClass)
function TestFunction2(generic_table, testclass_instance) end
-- TestFunction3
---@param generic_table table
function TestFunction3(generic_table) end
-- TestFunction3
---@param testclass_instance TestClass
function TestFunction3(testclass_instance) end
And then a lua code file contains a call to either test function like
TestFunction1({1,2,3})
TestFunction2({1,2,3})
TestFunction3({1,2,3})
LLS reports Missing required fields in type ``TestClass``: ``TestField`` Lua Diagnostics.(missing-fields) for all 3 calls. Instead it should accept the table as input parameter for the 3 functions.
Additional Notes
No response
Log File
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从复现代码中的 Lua 和类型注解入手,然后跟踪为 union 和 overload 参数生成缺失字段诊断的类型检查路径。完成的标准是:三次调用中的泛型表都能被接受,且不会报告缺少 TestClass.TestField;issue 中没有指明源文件或测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100