LuaLS / LuaLS/lua-language-server
`generic` inheritance does not work
オープン
まだ誰も着手していません。
enhancement
feat/generic
feat/LuaCats Annotations
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
The second case
Core = {};
---@class Rotation
---@field Enabled boolean
local Rotation = {}
function Rotation:OnLoad() end
function Rotation:OnUnload() end
---@class RotationEngine
Core.RotationEngine = {}
---@generic T
---@param name `T`
---@return T|Rotation rotation
function Core.RotationEngine.AddRotation(name) end
---@class MyRotation
---@field testfield table
local MyRotation = {};
function MyRotation:Test() end
local rotation = Core.RotationEngine.AddRotation("MyRotation");
---@param self MyRotation
---@return boolean
local function myFunc(self) end
local a = myFunc(rotation);
In the first case, in the MyRotation class, we seek methods of the Rotation class,

but also an error Cannot assign MyRotation|Rotation to parameter MyRotation.Lua Diagnostics.(param-type-mismatch)

The second case
Core = {};
---@class Rotation
---@field Enabled boolean
local Rotation = {}
function Rotation:OnLoad() end
function Rotation:OnUnload() end
---@class RotationEngine
Core.RotationEngine = {}
---@generic T: Rotation
---@param name `T`
---@return T rotation
function Core.RotationEngine.AddRotation(name) end
---@class MyRotation
---@field testfield table
local MyRotation = {};
function MyRotation:Test() end
local rotation = Core.RotationEngine.AddRotation("MyRotation");
---@param self MyRotation
---@return boolean
local function myFunc(self) end
local a = myFunc(rotation);
In the second case there is no inheritance

and there is no error either

コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue にある 2 つの Lua スニペットを再現し、rotation の推論された型、メソッド補完、診断を比較します。AddRotation に関係するジェネリックな戻り値型の推論とクラス継承の処理を追跡します。意図された継承メンバーが利用可能になり、2 つ目のケースの動作を失うことなく、誤った MyRotation|Rotation 型の不一致が解消されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100