LuaLS / LuaLS/lua-language-server
Missing diagnostic when passing nil-able fields to pairs/ipairs
まだ誰も着手していません。
- 主要言語
- 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
In the following code, I expect to get param-type mismatch for each of the for loops (with pairs and ipairs) because the variable being iterated can be nil:
---@type string[]?
local x1 = {}
for _ in ipairs(x1) do -- param-type-mismatch: Cannot assign `string[]?` to parameter `<T:table>
break
end
---@type table<string, boolean>?
local y1 = {}
for _ in ipairs(y1) do -- param-type-mismatch: Cannot assign `table<string, boolean>?` to parameter `<T:table>
break
end
---@class Class
---@field x string[]?
---@field y table<string, boolean>?
---@type Class
local x2 = {}
for _ in ipairs(x2.x) do -- Should warn, but it doesn't
break
end
for _ in pairs(x2.y) do -- Should warn, but it doesn't
break
end
Actual Behaviour
The param-type-mismatch diagnostic is only shown for the first two loops (direct variables without nesting/fields), but not when using fields (the third and fourth for loops).
Reproduction steps
Copy the code into a Lua file and observe the diagnostics
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Lua の例を Lua ファイルにコピーし、直接変数とネストされたフィールドの診断を比較して問題を再現します。ipairs と pairs の引数を処理する型チェックの経路を追跡し、nullable フィールドが直接変数と同じ param-type-mismatch 診断を受けることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100