LuaLS / LuaLS/lua-language-server
`---@cast` annotation doesn't respect scope rules
オープン
まだ誰も着手していません。
- 主要言語
- 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
Expected Behaviour
The ---@cast annotation should respect Lua scoping rules.
Actual Behaviour
Let's consider:
--- @class foo
--- @field a number
--- @class bar
--- @field b string
--- @type { [integer]: foo|bar }
local array = {}
for i, instance in ipairs(array) do
if instance.a then
-- First if block
--- @cast instance foo
end
if instance.b then
-- Second if block
end
end
In the first if block, we cast the instance to the foo type. When hovering over the instance variable in the second if block we can see its type is foo. It would be expected for its type to be bar since the ---@cast happened in different scope.
Reproduction steps
- Copy-paste the given example code into your text editor.
- Hover over the
instancevariable in the second if block. - See the error in the popup.
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Visual Studio Code 拡張機能で提供されている Lua の例を使って問題を再現し、型チェックが 2 つの if ブロックのスコープをどのように扱うかを調べます。完了条件は、foo へのキャストが最初のブロック内でのみ適用され、2 番目のブロックのインスタンスが foo ではなく適切な推論型を保持することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 42/100