LuaLS / LuaLS/lua-language-server
A union type should not merge class fields
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?
MacOS
What is the issue affecting?
Annotations
Expected Behaviour
---@class (exact) TypeA
---@field type 'A'
---@field commonField number
---@field specificFieldA number
---@class (exact) TypeB
---@field type 'B'
---@field commonField string
---@field specificFieldB string
---@alias Type_Either_A_Or_B_But_Not_Both TypeA|TypeB
---@type Type_Either_A_Or_B_But_Not_Both
local testA = {
type = 'A', --- Indicates that this should be of TypeA
commonField = 'test', --- Should be an error. TypeA.commonField should be a number
specificFieldA = 123, --- OK
specificFieldB = 'Hello' --- Should be an error. TypeA.specificFieldB doesn't exist
}
---@type Type_Either_A_Or_B_But_Not_Both
local testB = {
type = 'B', --- Indicates that this should be of TypeB
commonField = 'test', --- OK
specificFieldA = 123, --- Should be an error. TypeB.specificFieldA doesn't exist
specificFieldB = 'Hello' --- OK
}
Actual Behaviour
TypeA|TypeB is merged, so none of the mismatched fields/types are reported as errors.
local testA: TypeA|TypeB {
commonField: string|number,
specificFieldA: number,
specificFieldB: string,
type: 'A'|'B',
}
Reproduction steps
Paste the code into vscode
Additional Notes
No response
Log File
No response
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das annotierte TypeA|TypeB-Beispiel in der Visual Studio Code-Erweiterung und verfolge anschließend, wie der language server die Felder von Union-Klassen zusammenführt. Erledigt ist die Aufgabe, wenn der Diskriminator die richtige Klasse auswählt und die im Beispiel gezeigten nicht übereinstimmenden Felder commonField und die mitgliedsspezifischen Felder meldet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100