LuaLS / LuaLS/lua-language-server
Needs a "don't use truthy types in a conditional/boolean context" diagnostic
還沒有人認領這個 Issue。
- 主要語言
- 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?
Type Checking, Diagnostics/Syntax Checking
### Expected Behaviour
When variable `a` has a truthy type (e.g. any type that does not contain `boolean` or `nil`), then the following lines should all give warnings, since (assuming the type annotations are correct and `Weak Nil Check` is off) `a` cannot be `nil` or `false`, and thus can never resolve to `false` in a boolean context, and so the operations are pointless:
```lua
if a then print("1") end -- will always print 1
if not a then print("2") end -- will never print 2
local b = a or "3" -- equivalent to b = a
local c = a and "4" or "5" -- equivalent to c = "4"
```
### Actual Behaviour
None of those lines warn you about anything under the current diagnostics
### Reproduction steps
1. Type the following into a lua file:
```lua
---@param a number (or string, table, etc.)
function A(a)
if a then print("1") end
if not a then print("2") end
local b = a or "3"
local c = a and "4" or "5"
end
```
2. Observe the lack of diagnostic warnings on each line inside the function
(I would also like a "no-unparameterized-tables" diagnostic where plain `table` without any <> does not count as a valid type)
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先透過 Visual Studio Code 擴充功能,在 Lua 檔案中重現提供的 Lua 程式碼片段,然後追蹤處理條件式與布林運算式的型別檢查和診斷入口點。完成的標準是所要求的案例會產生適當的警告;另外也需要決定獨立的 no-unparameterized-tables 請求範圍。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- tooling
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100