LuaLS / LuaLS/lua-language-server
Optional not removed in if/elseif block for field in filter
オープン
まだ誰も着手していません。
- 主要言語
- 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?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
---@type { n: number? }
local t = { n = 1 }
if t.n then
_ = t.n -- (field) t.n: number
else
_ = t.n -- (field) t.n: number?
end
Actual Behaviour
---@type number?
local n = 0
if n then
_ = n -- local t: number
else
_ = n -- local t: nil
end
-- but
---@type { n: number? }
local t = { n = 1 }
if t.n then
_ = t.n -- (field) t.n: number? !!!
else
_ = t.n -- (field) t.n: number?
end
Additional Notes
I couldn't immediately understand where exactly this type casting is happening
Looks like here
https://github.com/LuaLS/lua-language-server/blob/34ff9d3ca730bc28879ab2b0c1a49f2c5480f9a3/script/vm/tracer.lua#L240-L243
but adding debug log nothing came out
I would be grateful for the information, I could try to fix it myself
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Visual Studio Code 拡張機能で 2 つの narrowing の例を再現し、その後、issue で言及されている場所である script/vm/tracer.lua の 240-243 行付近を調べます。完了条件は、if ブランチではフィールドアクセス t.n が number に絞り込まれ、else ブランチでは number? のままとなり、ローカル変数の挙動と一致することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100