LuaLS / LuaLS/lua-language-server
Ternary operator with optional arg unfolds to the wrong type
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported type-checking results in LuaLS using the four Lua snippets in the issue, including boolean, optional, nil, and default cases. Trace the type inference for the and expression and add regression coverage so the inferred result preserves the relevant string, boolean, false, and nil unions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100