LuaLS / LuaLS/lua-language-server
Class inheriting a generic class with specified type not recognized as inherited class (assign-type-mismatch)
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?
Type Checking
Expected Behaviour
The type of a class inheriting a generic class (when specifying the type) should be recognized as the same type as the class it inherits.
If that generic class inherits another class, that should also be recognized.
As such, the following code should have no problems.
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic<T> : Test_Base
--- @field Gen_T T
local Test_Generic = {}
--- @class Test_Class : Test_Generic<string>
local Test_Class = {}
--- @type Test_Base[]
local testArray = {
Test_Base,
Test_Generic,
Test_Class,
}
Actual Behaviour
"Test_Class" isn't recognized as either "Test_Generic" or "Test_Base", therefore showing as an "assign-type-mismatch" error.
However, inheriting the generic class without specifying the type is completely fine.
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic<T> : Test_Base
--- @field Gen_T T
local Test_Generic = {}
--- @class Test_Class : Test_Generic
local Test_Class = {}
--- @type Test_Base[]
local testArray = {
Test_Base,
Test_Generic,
Test_Class,
}
Reproduction steps
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic<T> : Test_Base
--- @field Gen_T T
local Test_Generic = {}
--- @class Test_Class1 : Test_Generic<string>
local Test_Class1 = {}
--- @class Test_Class2 : Test_Generic
local Test_Class2 = {}
--- @type Test_Base[]
local testArray = {
Test_Base,
Test_Generic,
Test_Class1,
Test_Class2,
}
Additional Notes
This problem showed up after the release of version 3.17.0
I know that the implementation of generics is complicated, and I've already found a workaround for my use-case by casting the inheriting classes to the type of the underlying base class. But that may not work for others.
Log File
No response
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione in Lua nell’issue e passala attraverso il controllo dei tipi dell’estensione Visual Studio Code per osservare la diagnostica assign-type-mismatch. Traccia la gestione dell’ereditarietà delle classi generiche, quindi verifica che Test_Class1 sia accettato sia come Test_Generic sia come Test_Base, incluso il caso di ereditarietà transitiva, mentre il comportamento esistente di Test_Class2 rimane valido.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100