LuaLS / LuaLS/lua-language-server
Function Prototype Narrowing with nils
未关闭
还没有人认领这个 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
Expected Behaviour
Foo.Bar('Baz', 'Qux') -- **string**
Foo.Bar('Baz', nil) -- nil
Foo.Bar('Baz') -- nil
Foo.Bar(nil, 'Qux') -- nil
Foo.Bar(nil, nil) -- nil
Foo.Bar() -- nil
Actual Behaviour
Foo.Bar('Baz', 'Qux') -- **string|nil**
Foo.Bar('Baz', nil) -- nil
Foo.Bar('Baz') -- nil
Foo.Bar(nil, 'Qux') -- nil
Foo.Bar(nil, nil) -- nil
Foo.Bar() -- nil
Reproduction steps
---@param baz string|number
---@param qux string|number
---@return string
---@overload fun(text: string|number, title: nil):nil
---@overload fun(text: nil, title: string|number):nil
---@overload fun(text: nil, title: nil):nil
function Foo.Bar(baz, qux)
if not baz or not qux then
return nil
end
return 'SomeString'
end
Additional Notes
It seems to match the 'strings' can be nil
First input example
Last input example
Log File
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行 issue 中的 Lua 复现,并比较每种参数组合推断出的返回类型。然后跟踪函数原型涉及的类型检查和重载解析路径,接着为预期的 narrowing 行为添加覆盖,并验证 non-nil 重载解析为 string,而 nil 情况解析为 nil。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100