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 use generic type in field #3043

Open
SLUCHABLUB opened this issue Jan 15, 2025 · 2 comments
Open

Cannot use generic type in field #3043

SLUCHABLUB opened this issue Jan 15, 2025 · 2 comments

Comments

@SLUCHABLUB
Copy link

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

MacOS

What is the issue affecting?

Type Checking

Expected Behaviour

That no error is shown.

Actual Behaviour

You receive the error: Undefined type or alias `B`.

Reproduction steps

---@class A<B>
---@field b B

Additional Notes

No response

Log File

No response

@tomlau10
Copy link
Contributor

tomlau10 commented Jan 15, 2025

for this specific use case, you may use:

---@class A<B>: { b: B }

---@type A<string>
local a = {}

print(a.b) --> (field) a.b: string
  • this roughly means that A<B> is a table like { b: B }
  • AFAIK luals's generic class support is quite limited currently
    and seems you can't directly use that generic variable inside @field

ps:
for questions / q&a, please consider using the discussion: https://github.com/LuaLS/lua-language-server/discussions
issue page is for tracking bugs / incorrect behavior / etc. 😅

edit:
I assume this is a feature request, so you may keep it open. 😂
Though I don't think maintainers will have time to finish it, given that it has workarounds/alternatives, and not a serious bug.

@CppCXY
Copy link
Collaborator

CppCXY commented Jan 15, 2025

image
I suggest you see: #3017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants