LuaLS / LuaLS/lua-language-server

`assign-type-mismatch` warning when overloading a derived class

Open
#2,468 0 comments 0 reactions 0 assignees View on GitHub

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
---@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:

- ---@class Parent
+ ---@class Parent : table
Log File

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.