Problem with methods of generic classes
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- lua
調査の方向性
Visual Studio Code拡張機能で、issueにある汎用的なFooの継承例を再現し、型チェックの診断結果を確認するためにservice.logを調べます。継承されたメソッドがジェネリックな戻り値の型をどのように置換するかを追跡し、そのうえでExample2とExample3についてget()がそれぞれstringとbooleanに解決され、誤った警告が導入されないことを確認します。
索引モデルが 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, Annotations
Expected Behaviour
- Define a generic base class Foo with a method function which returns the generic type
- Inherit from the base class and specify the generic type
- Use the method and expect the specified generic type on the output
---@class Foo<T>
---@field myValue T
local base = {}
---@return T
function base:get()
return self.myValue
end
---@type Foo<number>
local ex1 = base --Use class directly
---@class Example2 : Foo<string>
local ex2 = ex1 --Start with a version with generic type specified
---@class Example3 : Foo<boolean>
local ex3 = base --Start with a version without the generic type specified
local I = ex1.myValue --Correct: number
local a = ex1:get() --Correct: number
local II = ex2.myValue --Correct: string
local b = ex2:get() --Correct: string
local III = ex3.myValue --Correct: boolean
local c = ex3:get() --Correct: boolean
Actual Behaviour
Attempting to expand the parent class directly displays a warning, (Example 3) but using a variable with specified type does not (Example 2).
The method defined in the parent class fails to infer the generic type from the child classes
---@class Foo<T>
---@field myValue T
local base = {}
---@return T
function base:get()
return self.myValue
end
---@type Foo<number>
local ex1 = base
---@class Example2 : Foo<string>
local ex2 = ex1
---@class Example3 : Foo<boolean>
local ex3 = base --Cannot assign 'Foo' to 'Example3'
local I = ex1.myValue --Correct: number
local a = ex1:get() --Correct: number
local II = ex2.myValue --Correct: string
local b = ex2:get() --Incorrect: T
local III = ex3.myValue --Correct: boolean
local c = ex3:get() --Incorrect: T
Reproduction steps
- Define a generic base class with a method function which returns the generic type
- Inherit from the base class and specify the generic type
- Use the method and expect the specified generic type on the output
Additional Notes
No response
Log File
- 主要言語
- 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