LuaLS / LuaLS/lua-language-server

Generics in nested functions don't work for some annotations unless there are no arguments passed

未關閉
#3,001 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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?

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
![image](https://github.com/user-attachments/assets/b06780fd-deb6-418c-b23b-ff3788d891ac)
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
![image](https://github.com/user-attachments/assets/08f1a903-7655-4dea-a551-80838c8a4154)

### 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_

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先重現提供的三個 Lua 註解範例,並檢查外部函式接收引數時巢狀泛型型別的解析方式。將推斷出的型別與無引數情況及預期的 hover 結果進行比較。完成的標準是三個範例都能將其內部函式解析為具體型別,例如 number,同時維持現有的正確行為。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
lua
領域
devtools
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。