LuaLS / LuaLS/lua-language-server
Using LuaJIT's nil-coalescing extension does not narrow the type correctly
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?
Other
Which OS are you using?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
Using the nil-coalescing operator should narrow an expressions type. For example, in this sample code, the type of b should be narrowed to integer:
---@type integer?
local foo = 1
local bar = foo ?? 2
Actual Behaviour
Instead of the type being narrowed, the type of foo is copied instead, and the type of bar is thought to be integer? instead of integer.
Reproduction steps
- Insert the following sample code in a project:
---@type integer?
local foo = 1
local bar = foo ?? 2
- Check the type of
b
Additional Notes
This seems to work fine using the classic Lua approach with or:
---@type integer?
local foo = 1
local bar = foo or 2
The type of bar is integer here, as expected.
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
Beginne damit, das Problem im Typprüfer von lua-language-server mit dem bereitgestellten ??-Beispiel zu reproduzieren, und vergleiche anschließend den daraus abgeleiteten Typ mit dem der entsprechenden or-Expression. Verfolge, wie die Nil-Coalescing-Expression nullable Operanden verarbeitet; abgeschlossen ist die Aufgabe, wenn bar als integer abgeleitet wird und das bestehende Verhalten für den Vergleichsfall korrekt bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 68/100