LuaLS / LuaLS/lua-language-server
[Annotations] false positive param-type-mismatch on a class member function
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
### 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:
1. base class BaseWidget
2. BaseContainer which inherits from BaseWidget
3. 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:
```LUA
---@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_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the simplified Lua reproduction and inspect how the annotations and param-type-mismatch diagnostic are handled for inherited class member functions. Confirm the diagnostic at the Button.new(...):setAnchor(...) call, then verify that the corrected behavior covers this inheritance pattern without introducing new mismatches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100