LuaLS / LuaLS/lua-language-server
`assign-type-mismatch` warning when overloading a derived class
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?
Visual Studio Code Extension (sumneko.lua)
### Which OS are you using?
Windows
### What is the issue affecting?
Annotations, Type Checking, Diagnostics/Syntax Checking
### Expected Behaviour
No warning generated.
### Actual Behaviour
An `assign-type-mismatch` warning is thrown.
### Reproduction steps
```lua
---@class Parent
---@return Parent
local function newParent() local o = {}; return setmetatable(o, o) end
---@class Object : Parent
---@overload fun(s: string) -- Or disable the diagnostic on this line
local o = newParent() -- Invalid warning here
function o:__call() end
```
### Additional Notes
The overload workaround, mentioned in #1733 does not work in this use case. A function returns a type, from which a new class is created. When overloading this new class, an invalid warning is generated.
ℹ️ A workaround I've found is to make the class derive also from `table`:
```diff
- ---@class Parent
+ ---@class Parent : table
```
### 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
Reproduce the warning from the Lua snippet in the Visual Studio Code extension, focusing on the `assign-type-mismatch` diagnostic when `@overload` is applied to a class returned by a function. Trace the handling of `@class` inheritance and overloads, then verify that the reproduction no longer emits the invalid warning while preserving the documented `table` workaround behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100