LuaLS / LuaLS/lua-language-server
[Annotations] false positive param-type-mismatch on a class member function
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Lua
- Star
- 4.4k
- Fork
- 442
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với bản tái hiện Lua đơn giản hóa và kiểm tra cách các chú thích cùng chẩn đoán param-type-mismatch được xử lý đối với các hàm thành viên lớp được kế thừa. Xác nhận chẩn đoán tại lệnh gọi Button.new(...):setAnchor(...), sau đó kiểm tra rằng hành vi đã được sửa bao quát mẫu kế thừa này mà không tạo ra các mismatch mới.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- lua
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100