LuaLS / LuaLS/lua-language-server
When the subclass inherits the constructor of the parent class, generics do not work (the type of `self` cannot be used for annotation)
まだ誰も着手していません。
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
How are you using the lua-language-server?
Other
Which OS are you using?
Windows
What is the issue affecting?
Annotations, Type Checking
Expected Behaviour
---@class Vehicle
Vehicle = {}
---comment
---@generic T
---@param self `T`
---@param o? T
---@return T
function Vehicle:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
---@class Plane: Vehicle
Plane = {}
setmetatable(Plane, { __index__ = Vehicle })
local obj = Plane.new()
The code prompt given when calling a constructor annotated with generic parameters that is inherited by a subclass is incorrect.
The prompt message should be
function Plane.new(self: Plane, o?: Plane)
And the type of the obj variable in the code hint should be Plane instead of unknown
Actual Behaviour
---@param o? self
---@return self
function Vehicle:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
self should be used to refer to the type of the method caller. And the self method should replace the generic method to annotate the type in this use case
Such type annotations should work, and code completion should show self as the caller's type
Reproduction steps
- Copy example to editor
- Call code prompt
- The prompt result is not as expected
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された Vehicle と Plane の例をエディターで再現し、継承されたメソッドに対するコンストラクターのジェネリックと self 型の推論を追跡します。コードプロンプトに function Plane.new(self: Plane, o?: Plane) が表示され、obj の推論された型が unknown ではなく Plane であることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100