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

cannot extend generic class #1929

Open
somebody1234 opened this issue Feb 20, 2023 · 6 comments
Open

cannot extend generic class #1929

somebody1234 opened this issue Feb 20, 2023 · 6 comments
Labels
duplicate This issue or pull request already exists feat/generic Related to generic emulation feature

Comments

@somebody1234
Copy link

somebody1234 commented Feb 20, 2023

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Type Checking

Expected Behaviour

inheritance works, or error diagnostic

Actual Behaviour

inheritance doesnt work, no diagnostic

Reproduction steps

--- @class Foo<t>: { a: t; }
--- @class Bar: Foo<integer>
local x --- @type Bar
local what = x.a -- type is unknown

Additional Notes

seems like it just doesnt handle generic syntax in : here?

Log File

No response

@carsakiller
Copy link
Collaborator

There are just so many issues about generics and generic classes 😰

Going to close this one as a duplicate of #1863 or #1378

@carsakiller carsakiller added duplicate This issue or pull request already exists feat/generic Related to generic emulation feature labels Feb 20, 2023
@carsakiller carsakiller closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2023
@somebody1234
Copy link
Author

@carsakiller saw those from the generics super issue, but afaict this is a different issue

@somebody1234
Copy link
Author

the issue here is : Foo<t> just flat out doesn't work

@carsakiller
Copy link
Collaborator

Yes, but the bottom line is really that --- @class Foo<t>: { a: t } doesn't work because generic classes are not supported. The ---@class Child: Parent syntax is supported elsewhere, so when generic classes are implemented, Child : Parent<T> should also work. This is the first time I have seen this syntax mentioned though, I think, so I'll add it to the list just so we can make sure it receives some attention.

Just trying to keep things organized—there are so many similar issues with slight variations 😄

@carsakiller carsakiller reopened this Feb 20, 2023
@somebody1234
Copy link
Author

i was assuming it does work though:

  • the docs mention it
    • (the builtin table and array are generic classes afaict)
  • it works if you're not doing : Foo<t>

image

@carsakiller
Copy link
Collaborator

I see, I thought the generic class was not working when inheriting { a: t } as well. It seems it does though.

--- @class Foo<t>: { a: t; }

---@type Foo<integer>
local x
print(x.a) -- Type is integer


---@class Bar : Foo<integer>

---@type Bar
local y
print(y.a) -- undefined field `a`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists feat/generic Related to generic emulation feature
Projects
None yet
Development

No branches or pull requests

2 participants