LuaLS / LuaLS/lua-language-server

Class Inheritance Triggers Typing Issues

Aperta
#1,893 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

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](https://user-images.githubusercontent.com/39225561/217849625-8341465c-2717-438d-940f-c31cb41e0a7d.png)

### Reproduction steps

1. Create a superclass:
```
---@class MySuperclass
local o = {}
```
2. Create a subclass:
```
---@class MySubclass : MySuperclass
local o = {}
```
3. Create a function that returns MySuperclass
4. 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](https://github.com/LuaLS/lua-language-server/files/10698513/file_s.3A_modding_warhammer_3_groovy_mct.log)

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 gli esempi di superclasse e sottoclasse presenti nell’issue tramite l’estensione di Visual Studio Code su Windows, concentrandoti sulla diagnostica del controllo dei tipi per l’assegnazione di un risultato MySuperclass a MySubclass. Traccia il comportamento del controllo dei tipi coinvolto nell’ereditarietà delle classi e conferma che, una volta completata la correzione, l’assegnazione viene accettata senza richiedere @cast.

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
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.