LuaLS / LuaLS/lua-language-server

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

Aperta
#3,001 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Lua
Stelle
4.4k
Fork
442
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo i tre esempi di annotazioni Lua forniti e verifica come vengono risolti i tipi generici annidati quando la funzione esterna riceve un argomento. Confronta i tipi dedotti con i casi senza argomenti e con i risultati di hover previsti. Il lavoro è completato quando tutti e tre gli esempi risolvono le proprie funzioni interne nel tipo concreto, ad esempio number, preservando al contempo il comportamento corretto esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
lua
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.