LuaLS / LuaLS/lua-language-server

`@overload` does not cooperate with `@class` when adding overloads to an inherited class method

Offen
#3,364 1 Kommentar 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?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Completion

Expected Behaviour

Adding an overload to a function inherited from another class should result in both the parent class' overloads and the new overload being suggested as autocomplete and hover tooltip entries.

Actual Behaviour

Adding an overload to a function inherited from another class makes that overload the only one that is recognized for the current class.

Reproduction steps
---@meta

---@class ParentClass
ParentClass = {}

---@param arg string
---@return unknown
---@overload fun(self, arg: "bar"): boolean
function ParentClass:foo(arg) end

---@class ChildClass : ParentClass
---@field foo fun(self, arg: "baz"): number
ChildClass = {}

ChildClass:foo(--[[Should suggest both "bar" and "baz", but only suggests "baz" and "bar" raises a param-type-mismatch]])

Redefining the function and adding an @overload there yields the same result.

Additional Notes

Having some way to mark a function redefinition as an overload (with strict checking that it does exist in the class defined as inherited from) would probably help solve this issue.

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 mit dem in der Reproduktion gezeigten Lua-Annotations- und Completion-Verhalten und konzentriere dich darauf, wie @class-Vererbung und @overload-Deklarationen behandelt werden. Reproduziere den Fall in NeoVim und überprüfe, dass Completion und Hover sowohl den geerbten "bar"-Overload als auch den "baz"-Overload des Kindtyps ohne eine Nichtübereinstimmung der Parametertypen anzeigen.

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
45/100

Neue Issues direkt in Ihr Postfach

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