LuaLS / LuaLS/lua-language-server
Lua Language Server Fails to Infer Type When Passing Multiple Return Values to Generic Function
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
### How are you using the lua-language-server?
NeoVim
### Which OS are you using?
MacOS
### What is the issue affecting?
Type Checking
### Expected Behaviour
```lua
---@return integer
---@return string
local f = function()
return 1, "a"
end
---@generic T
---@generic U
---@param t T
---@param u U
---@return U
local g = function(t, u)
return u
end
local x = g(f())
```
When the function g is called with the multiple return values of f, the Lua Language Server should infer the type of x based on the second return value of f (string), corresponding to the second generic type parameter (U) in g.
### Actual Behaviour
The Lua Language Server fails to infer the type of x. Instead, the type is left unknown.
### Reproduction steps
1. Write the following Lua code in an editor with the Lua Language Server enabled:
```lua
---@return integer
---@return string
local f = function()
return 1, "a"
end
---@generic T
---@generic U
---@param t T
---@param u U
---@return U
local g = function(t, u)
return u
end
local x = g(f())
```
2. Observe the type inference for x.
3. Note that the type of x is not inferred as string as expected.
### Additional Notes
_No response_
### Log File
_No response_
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先,在啟用 Lua Language Server 的 NeoVim 中重現這段 Lua 程式碼,並檢查接收多個回傳值的呼叫所經過的泛型型別推導路徑。完成標準是變數 x 被推導為 string,與 f 的第二個回傳值和泛型參數 U 相符。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100