Skip to content

Param type mismatch with indirect inheritance #2004

@firas-assaad

Description

@firas-assaad

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?

Diagnostics/Syntax Checking

Expected Behaviour

I expect the following example to work without any issues (it worked in the past):

---@class A
local A = {}

---@class B : A
local B = {}

---@class C : B
local C = {}

---@class D : B
local D = {}

---@overload fun(self : A, s : string)
function A:func() end

---@type D|C
local var
var:func('hi')

There should be no errors when calling the function overload var:func('hi')

Actual Behaviour

image

Cannot assign `C|D` to parameter `A`.
- `C` cannot match `A`
- Type `C` cannot match `A`
- Type `B` cannot match `A`

Reproduction steps

Try the example above with the latest VS Code extension

Additional Notes

From my testing, it only seems to happen when all of the following features are combined:

  • Indirect inheritance (C is a child of B which is a child of A)
  • Using a union type of two or more classes that indirectly inherit from a type (C|D)
  • Calling an overloaded version of a method (@overload fun(self : A, s : string))

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions