Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param type mismatch with indirect inheritance #2004

Closed
firas-assaad opened this issue Mar 12, 2023 · 3 comments
Closed

Param type mismatch with indirect inheritance #2004

firas-assaad opened this issue Mar 12, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@firas-assaad
Copy link
Contributor

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

@RomanSpector
Copy link

I think it should be written like this

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

In that case, self would be C|D

I think it's related: #2002

@firas-assaad
Copy link
Contributor Author

I think it should be written like this

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

In that case, self would be C|D

I think it's related: #2002

If you write it like that you lose the type information when hovering:
image

I also tried writing it as ---@overload fun(self, s : string), but then you see self as any.

Also if you don't use a union type (e.g. use D instead of C|D) then the example works fine, and you see self : A when hovering, so there's something inconsistent with union types:

image

I'm not sure if your issue is related since I don't know how these features are implemented. Could be!

@sumneko sumneko added the bug Something isn't working label Mar 13, 2023
@firas-assaad
Copy link
Contributor Author

Works great. Thanks for fixing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants