Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Class inheriting a generic class with specified type not recognized as inherited class (assign-type-mismatch)

オープン
#3,345 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
lua
領域
tooling

調査の方向性

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.

Image

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

LuaLS/lua-language-server のほかの issue

LuaLS/lua-language-server の issue をすべて見る

似ている issue

Lua の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。