LuaLS / LuaLS/lua-language-server
[Annotations] false positive param-type-mismatch on a class member function
オープン
まだ誰も着手していません。
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Linux
What is the issue affecting?
Annotations
Expected Behaviour
I believe there should be no param-type-mismatch error or such cases should have better documentation if there's a workaround available.
Actual Behaviour
I have a following class structure:
- base class BaseWidget
- BaseContainer which inherits from BaseWidget
- DialogWindow which inherits from BaseContainer
Creating a member function in DialogWindow and calling it results in an param-type-mismatch error.
Reproduction steps
Issue can be reproduced with the following simplified code snippet:
---@class BaseWidget
---@field _config table
---@field uiObject table
---@field build fun(BaseWidget, boolean)
local BaseWidget = {}
BaseWidget.__index = BaseWidget
---@return BaseWidget
function BaseWidget.new()
local instance = setmetatable({}, BaseWidget)
instance._config = {}
instance.uiObject = nil
instance:setAnchor(0, 0)
return instance
end
function BaseWidget:setAnchor(left, top, right, bottom)
print("Base setAnchor")
return self
end
---@class BaseContainer: BaseWidget
local BaseContainer = BaseWidget.new()
BaseContainer.__index = BaseContainer
---@return BaseContainer|BaseWidget
function BaseContainer.new()
---@type BaseContainer|BaseWidget
local instance = setmetatable(BaseWidget.new(), BaseContainer)
instance.uiObject = nil
return instance
end
function BaseWidget:addRow()
print("BaseContainer addRow")
return self
end
---@class Button: BaseWidget
---@field uiObject table
---@field parent table
local Button = BaseWidget.new()
Button.__index = Button
function Button.new(label, icon)
local button = setmetatable(BaseWidget.new(), Button)
return button
end
function Button:build(parent)
print("btn build")
end
---@class DialogWindow: BaseContainer
---@field baseInput table
---@field frame table
local DialogWindow = BaseContainer.new()
DialogWindow.__index = DialogWindow
function DialogWindow.new(dialogWidth)
local window = setmetatable(BaseContainer.new(), DialogWindow)
window:append(Button.new("Test00", nil):setAnchor(0, 0)) -- param-type-mismatch error shows up here
return window
end
---@param uiObj BaseWidget
function DialogWindow:append(uiObj)
uiObj:build(self.frame)
end
Additional Notes
No response
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
簡略化されたLuaの再現コードから始め、継承されたクラスメンバー関数について、アノテーションとparam-type-mismatch診断がどのように処理されるかを調べます。Button.new(...):setAnchor(...)の呼び出しで診断を確認し、修正後の動作が新たなmismatchを導入することなく、この継承パターンをカバーしていることを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100