LuaLS / LuaLS/lua-language-server
Ternary operator with optional arg unfolds to the wrong type
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?
Windows
What is the issue affecting?
Annotations, Type Checking
Expected Behaviour
Ternary operators give out the correct type, process logical conditions correctly.
Actual Behaviour
must be string|false without default or string|boolean or "yes"|false. but not "yes" as default

condition can be boolean or nil, but actual result the same, cannot be optional |nil, ?


can't be nil

so my real case gives boolean|string or boolean|string|false boolean|string = false but without ?

Reproduction steps
---@type boolean
local cond
local value = cond and "yes"
---@type boolean?
local cond
local value = cond and "yes"
---@type boolean|nil
local cond
local value = cond and "yes"
---@type nil
local cond
local value = cond and "yes"
Additional Notes
Имя: Lua
Идентификатор: sumneko.lua
Описание: Lua Language Server coded by Lua
Версия: 3.6.11
Издатель: sumneko
Ссылка на Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=sumneko.lua
Версия: 1.75.1 (system setup)
Фиксация: 441438abd1ac652551dbe4d408dfcec8a499b8bf
Дата: 2023-02-08T21:32:34.589Z
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Windows_NT x64 10.0.19044
Изолированные: No
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 die gemeldeten Ergebnisse der Typprüfung in LuaLS anhand der vier Lua-Snippets im Issue, einschließlich der Fälle boolean, optional, nil und default. Verfolge die Typinferenz für den and-Ausdruck und füge eine Regressionstestabdeckung hinzu, sodass das inferierte Ergebnis die relevanten Vereinigungen aus string, boolean, false und nil beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua, vscode
- 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