LuaLS / LuaLS/lua-language-server
Class inheriting a generic class with specified type not recognized as inherited class (assign-type-mismatch)
まだ誰も着手していません。
- 主要言語
- 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 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.
``` Lua
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic : 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,
}
```
### 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.
``` Lua
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic : 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
``` Lua
--- @class Test_Base
--- @field Str_A string
local Test_Base = {}
--- @generic T
--- @class Test_Generic : Test_Base
--- @field Gen_T T
local Test_Generic = {}
--- @class Test_Class1 : Test_Generic
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_
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Start with the Lua reproduction in the issue and run it through the Visual Studio Code extension's type checking to observe the assign-type-mismatch diagnostic. Trace generic-class inheritance handling, then verify that Test_Class1 is accepted as both Test_Generic and Test_Base, including the transitive inheritance case, while the existing Test_Class2 behavior remains valid.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100