LuaLS / LuaLS/lua-language-server
Widening cast has no effect
まだ誰も着手していません。
- 主要言語
- 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?
Annotations, Type Checking, Hover
Expected Behaviour
Cast unconditionally overwrites the variable's type with the new type.
Actual Behaviour
Cast is ignored and in some cases causes additional type check errors.
Reproduction steps
---@param str string
local function foo(str)
---@cast str +?
if str == '' then str = nil end
end
Note how it produces an error on assignment:
This variable is defined as type `string`. Cannot convert its type to `nil`.
- `nil` cannot match `string`
- Type `nil` cannot match `string` Lua Diagnostics.(cast-local-type)
Note also that the tooltip for str in the comparison says correctly that it is a string?. But this has no observable effect on the actual type.
Example two (attempted workaround):
---@param str string
local function foo(str)
---@cast str string?
if str == '' then str = nil end
end
Note how the cast causes a type check error now, which makes no sense.
Example three (from the wiki on cast, modified to actually verify that the cast worked):
---@type integer
local x
---@cast x +boolean
x = false
Note how it produces an error, similarly to the first example. You would expect at least the example from the official documentation itself to work, but it doesn't. This leads me to conclude this is a bug.
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず issue にある 3 つの Lua の再現コードを実行し、ホバー情報と代入診断を比較します。ローカル変数に対する cast の処理と、その後の型チェックの経路を追跡します。次に、widening cast が代入チェックに影響し、矛盾するエラーを導入しないように、カバレッジを追加または更新します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100