LuaLS / LuaLS/lua-language-server
`need-check-nil` doesn't recognize nil check propagation
まだ誰も着手していません。
- 主要言語
- 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?
MacOS
What is the issue affecting?
Diagnostics/Syntax Checking
Expected Behaviour
Ideally, need-check-nil would infer a nil check has been completed if I've already done that nil check earlier as part of a larger check. Specifically, the statement if not (a and a.b) then will properly register as a nil check on a, but assigning the inner expression to a local var prevents LLS from detecting it as a nil check.
Actual Behaviour
LLS warns need-check-nil when a variable cannot possibly be nil, if the check was masked via another variable.
Reproduction steps
---@return table?
local function stuff()
return nil
end
local item = stuff()
local x = item and item.x
if not x then -- Works: `if not (item and item.x) then`
-- This includes case where `item` is `nil`
else
local subitem = item.key -- Error on `item` (need-check-nil)
end
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Issue にある Lua の例を使って Visual Studio Code 拡張機能で need-check-nil 診断を再現し、次に診断の nil-check 伝播ロジックを追跡します。以前の x を通したチェックによって item が nil ではないことがすでに除外されている場合に、例で item.key に対する警告が出なくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua, vscode
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100