LuaLS / LuaLS/lua-language-server

Ternary operator with optional arg unfolds to the wrong type

未關閉
#1,941 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。