LuaLS / LuaLS/lua-language-server
Proposal consider vararg returns as forced optional
还没有人认领这个 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?
Diagnostics/Syntax Checking
### Expected Behaviour
I suggest consider **vararg returns** as **optional** (can be `nil`) because no one guarantees that they will be filled in. The same goes for arguments, despite the fact that their type can also be optional or nilable.
If we return at least something, but we don't know the quantity, then the first argument won't be vararg - `any, any ...`.
Thus after that we do not need to additionally specify that the vararg returns is optional.
```lua
---@param a string
function test(a) end
---@param ... string
---@return string ...
function f(...) end
local a, b, c = f() --no warn
local a, b, c = f("1")
test(a) --no warn, expected optinal cannot match
---@param ... string?
---@return string? ...
function f(...) end
local a, b, c = f() --no warn
local a, b, c = f("1")
test(a) --warn optinal cannot match
---@param ... string|nil
---@return string|nil ...
function f(...) end
local a, b, c = f() --no warn
local a, b, c = f("1")
test(a) --warn nil cannot match
```
### Actual Behaviour
Vararg arguments are optional, but vararg returns are not.

### Reproduction steps
1. Make vararg return of some existing type.
2. It is guaranteed to be infinite - not optional or nil.
### Additional Notes
_No response_
### Log File
_No response_
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Lua language server 对 vararg 参数和返回值的诊断与类型推断处理入手,使用复现步骤和示例作为行为指南。验证 vararg 返回值在适当情况下会被视为 optional 或 nilable,同时确保提供的调用分别产生预期的警告和不产生警告。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100