LuaLS / LuaLS/lua-language-server

Lua Language Server Fails to Infer Type When Passing Multiple Return Values to Generic Function

オープン
#3,007 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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_

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、Lua Language Serverを有効にした状態でNeoVim上でLuaスニペットを再現し、複数の戻り値を受け取る呼び出しに対するジェネリック型推論の経路を調査します。完了条件は、変数 x が string と推論され、f の2番目の戻り値およびジェネリックパラメーター U と一致することです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。