LuaLS / LuaLS/lua-language-server

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

Offen
#3,001 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Lua
Sterne
4.4k
Forks
442
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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:

---@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(): <T>` with an unresolved generic
---@class POOL2<T>: { EnumerateActive: fun():(T, fun():T)) }
---@type POOL2<number>
local headerPool = {}
local number, func = headerPool:EnumerateActive()
-- number type is `number`
-- func type should be `fun(): number`, instead it's `fun(): <T>` with an unresolved generic
---@alias POOL3<T> fun(arg: number): T, (fun():T)
---@type POOL3<number>
local getPool
local number, func = getPool(3)
-- number type is `number`
-- func type should be `fun(): number`, instead it's `fun(): <T>` 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
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

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die drei bereitgestellten Lua-Annotationsbeispiele zu reproduzieren, und untersuche, wie verschachtelte generische Typen aufgelöst werden, wenn die äußere Funktion ein Argument erhält. Vergleiche die inferierten Typen mit den Fällen ohne Argumente und den erwarteten Hover-Ergebnissen. Die Aufgabe ist abgeschlossen, wenn alle drei Beispiele ihre inneren Funktionen in den konkreten Typ, beispielsweise number, auflösen und dabei das bestehende korrekte Verhalten erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
lua
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.