镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

cannot extend generic class  #1929

Closed
Closed

Description

@somebody1234

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

Activity

  1. carsakiller commented on Feb 20, 2023

    @carsakiller
    Collaborator

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

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

  2. added
    duplicateThis issue or pull request already exists
    feat/genericRelated to generic emulation feature
    on Feb 20, 2023
  3. somebody1234 commented on Feb 20, 2023

    @somebody1234
    Author

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

  4. somebody1234 commented on Feb 20, 2023

    @somebody1234
    Author

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

  5. carsakiller commented on Feb 20, 2023

    @carsakiller
    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 😄

  6. somebody1234 commented on Feb 20, 2023

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

  7. carsakiller commented on Feb 20, 2023

    @carsakiller
    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`
  8. added a commit that references this issue on Jan 11, 2026
    5d44a98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existsfeat/genericRelated to generic emulation feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions