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