LuaLS / LuaLS/lua-language-server
string.unpack vararg returns
還沒有人認領這個 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?
Linux
### What is the issue affecting?
Annotations, Type Checking, Completion
### Expected Behaviour
The current `string.unpack` annotations (for the returns) are as following:
```lua
---@param fmt string
---@param s string
---@param pos? integer
---@return any ...
---@return integer offset
---@nodiscard
function string.unpack(fmt, s, pos) end
```
The function will indeed return any number of `any` returns followed by a single integer return for the new offset. As such you would expect that in the following example code, all of the returns are `any` except the last return be `integer`:
```lua
local a, b, c, d, offset = string.unpack('I2I2I2I2', "some binary data")
```
### Actual Behaviour
Instead of the `a, b, c, d` being typed as `any` and `offset` being typed as `integer`, we instead see that `a` is typed as `any`, `b` is typed as `integer`, and `c, d, offset` are typed as `nil`.
This happen because it is not supported for a function to return a vararg followed by any return; it is always that vararg returns are the last return. Because of that, only the first return is typed as `any` and from there the second `@return` takes.
### Reproduction steps
1. Copy the example code.
2. Hover over each return variable to notice the type.
### Additional Notes
_No response_
### Log File
_No response_
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 string.unpack 註解開始,並在 Visual Studio Code 擴充功能中將滑鼠停留在每個回傳的變數上,以重現此問題。追蹤型別檢查器如何處理後接 offset 回傳值的 vararg。完成的標準是 unpack 值的型別為 any,且最後的 offset 型別為 integer。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100