LuaLS / LuaLS/lua-language-server

Class Inheritance Triggers Typing Issues

Offen
#1,893 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

question
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?

Type Checking, Diagnostics/Syntax Checking

Expected Behaviour

To put it in plain terms, this is for a system of UserControls for a settings-panel system. There is a single Superclass, called "MCT.Option", which houses all of the unified behavior of all the UserControls. Then there are subclasses, for each type of UserControl - checkbox, dropdown, etc.

There's an abstracted method on the UserControl "holders", holder:get_option_by_key("user_control_key') that I have annotated as returning an MCT.Option. In reality, that superclass is never actually returned in practice - it's purely abstracted, and any option is one of the several subclasses.

So when I call:

---@type MCT.Option.Checkbox
local option = holder:get_option_by_key("i_know_this_is_a_checkbox")

I'm expecting to very easily call a conversion from superclass -> subclass.

I have all that (I think) I need to tell the debugger that it's a subclass: initial definition of the subclass is ---@class MCT.Option.Checkbox : MCT.Option, Class to tell it its parents, and it reads from the higher methods and properties completely fine.

But when I call ---@type like that, the debugger doesn't let me simply convert from one to another.

I can of course use ---@cast option MCT.Option.Checkbox after the variable is defined, but that's a bit clunkier in my opinion than having the type defined above the variable, and it ends up requiring me to reference the variable in the annotation, so it takes a bit longer to write up (and I have a lot of these!)

Actual Behaviour

image

Reproduction steps
  1. Create a superclass:
---@class MySuperclass 
local o = {}
  1. Create a subclass:
---@class MySubclass : MySuperclass 
local o = {}
  1. Create a function that returns MySuperclass
  2. Try to direct the type that returns from that function into MySublass
Additional Notes

Thank you for all the hard work you've done over the years - I've been using this extension for a very very long time and it's truly a lifesaver.

Log File

file_s%3A_modding_warhammer_3_groovy_mct.log

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

Beginnen Sie damit, die Superklassen- und Unterklassenbeispiele aus dem Issue über die Visual Studio Code-Erweiterung unter Windows zu reproduzieren, wobei Sie sich auf die Typprüfungsdiagnose für die Zuweisung eines MySuperclass-Ergebnisses zu MySubclass konzentrieren. Verfolgen Sie das bei der Klassenvererbung beteiligte Verhalten der Typprüfung und bestätigen Sie, dass die Zuweisung nach Abschluss der Korrektur akzeptiert wird, ohne @cast zu erfordern.

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
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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