LuaLS / LuaLS/lua-language-server
Generics in nested functions don't work for some annotations unless there are no arguments passed
まだ誰も着手していません。
- 主要言語
- 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?
Annotations
### Expected Behaviour
passing an argument should have no effect, and the types of nested functions should be resolved correctly
some examples:
```lua
---@generic T
---@param arg T
---@return fun(): fun(): T
local function POOL1(arg) return function() return function() return arg end end end -- implementing the function makes no difference for the typing
local func1 = POOL1(5.2) -- type is `fun(): fun(): number`
local func2 = func1(4) -- type should be `fun(): number`, instead it's `fun(): ` with an unresolved generic
```
```lua
---@class POOL2: { EnumerateActive: fun():(T, fun():T)) }
---@type POOL2
local headerPool = {}
local number, func = headerPool:EnumerateActive()
-- number type is `number`
-- func type should be `fun(): number`, instead it's `fun(): ` with an unresolved generic
```
```lua
---@alias POOL3 fun(arg: number): T, (fun():T)
---@type POOL3
local getPool
local number, func = getPool(3)
-- number type is `number`
-- func type should be `fun(): number`, instead it's `fun(): ` with an unresolved generic
```
all 3 examples work fine if you don't pass any argument
### Actual Behaviour
when an argument is passed to the outer function, the inner function doesn't have the generic resolved

if no arguments are passed (i.e. `headerPool.EnumerateActive()`), then they _are_ resolved properly
the type of the argument makes no difference, and annotating the function as accepting an argument also makes no difference
interestingly, when hovering over the function itself, the tooltip does show the correctly resolved types

### Reproduction steps
copy the provided snippets, and check which types the variables resolve to
### Additional Notes
Tested on both VSCode and Jetbrains IDEs
The example is contrived, my real usecase is to annotate an object pool class, that allows you to acquire objects of a given (generic) type, and allows iterating over them.
I know this has worked in a past version, though I don't remember how long ago that was (several weeks or months most likely)
### Log File
_No response_
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供されている3つのLuaアノテーション例を再現し、外側の関数が引数を受け取るときにネストされたジェネリック型がどのように解決されるかを調べます。推論された型を、引数がない場合および期待されるホバー結果と比較します。3つの例すべてで、既存の正しい動作を維持しながら、内部関数が number などの具体的な型に解決されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 48/100