LuaLS / LuaLS/lua-language-server
Ternary operator with optional arg unfolds to the wrong type
未关闭
还没有人认领这个 Issue。
enhancement
question
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 issue 中的四个 Lua 代码片段,在 LuaLS 中重现报告的类型检查结果,包括 boolean、optional、nil 和 default 情况。跟踪 and 表达式的类型推断,并添加回归覆盖,确保推断结果保留相关的 string、boolean、false 和 nil 联合类型。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua, vscode
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100