Class inheriting a generic class with specified type not recognized as inherited class (assign-type-mismatch)
まだ誰も着手していません。
評価
調査の方向性
issue 内の Lua 再現から始め、それを Visual Studio Code 拡張機能の型チェックに通して、assign-type-mismatch 診断を確認します。ジェネリッククラスの継承処理を追跡し、推移的継承の場合も含めて、Test_Class1 が Test_Generic と Test_Base の両方として受け入れられることを確認します。その一方で、既存の Test_Class2 の動作は有効なままにします。
索引モデルが issue の本文から書いたものです。
説明
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 type of a class inheriting a generic class (when specifying the type) should be recognized as the same type as the class it inherits.
If that generic class inherits another class, that should also be recognized.
As such, the following code should have no problems.
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic<T> : Test_Base
--- @field Gen_T T
local Test_Generic = {}
--- @class Test_Class : Test_Generic<string>
local Test_Class = {}
--- @type Test_Base[]
local testArray = {
Test_Base,
Test_Generic,
Test_Class,
}
Actual Behaviour
"Test_Class" isn't recognized as either "Test_Generic" or "Test_Base", therefore showing as an "assign-type-mismatch" error.
However, inheriting the generic class without specifying the type is completely fine.
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic<T> : Test_Base
--- @field Gen_T T
local Test_Generic = {}
--- @class Test_Class : Test_Generic
local Test_Class = {}
--- @type Test_Base[]
local testArray = {
Test_Base,
Test_Generic,
Test_Class,
}
Reproduction steps
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic<T> : Test_Base
--- @field Gen_T T
local Test_Generic = {}
--- @class Test_Class1 : Test_Generic<string>
local Test_Class1 = {}
--- @class Test_Class2 : Test_Generic
local Test_Class2 = {}
--- @type Test_Base[]
local testArray = {
Test_Base,
Test_Generic,
Test_Class1,
Test_Class2,
}
Additional Notes
This problem showed up after the release of version 3.17.0
I know that the implementation of generics is complicated, and I've already found a workaround for my use-case by casting the inheriting classes to the type of the underlying base class. But that may not work for others.
Log File
No response
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- 平均マージ
- 8日 9時間
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
LuaLS/lua-language-server のほかの issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
LuaLS/lua-language-server#1776 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
LuaLS/lua-language-server#3463 · コメント 5 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
LuaLS/lua-language-server#3461 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
LuaLS/lua-language-server#3460 · コメント 1 件 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
LuaLS/lua-language-server#3459 · リアクション 1 件 ·
LuaLS/lua-language-server の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
LandSandBoat/server#11579 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ArchiveTeam/sinavideo-grab#7 · リアクション 3 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
mailcow/mailcow-dockerized#7480 ·
-
mapper bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100