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

Integer table indexes are incorrectly inferred #1831

Closed
firas-assaad opened this issue Jan 18, 2023 · 0 comments
Closed

Integer table indexes are incorrectly inferred #1831

firas-assaad opened this issue Jan 18, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@firas-assaad
Copy link
Contributor

firas-assaad commented Jan 18, 2023

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?

Type Checking, Hover

Expected Behaviour

Consider:

local enum = { a = 1, b = 2 }

local t = {
    [enum.a] = true,
    [enum.b] = 2,
    [3] = {}
}

When hovering over the table t, I see:

image

local t: {
    ["a"]: boolean = true,
    ["b"]: integer = 2,
    [3]: table
}

It's not only about hovering though, for example:

---@type { [integer] : boolean }
local t = {
    [enum.a] = true,
    [enum.b] = 2,
    [3] = {}
}

I only get a type warning for the index [3] = {}, and no warnings for [enum.b] = 2.

Actual Behaviour

The hover should show:

local t: {
    [1]: boolean = true,
    [2]: integer = 2,
    [3]: table
}

And in the example with @type { [integer] : boolean }, I should get a warning about incorrect values.

Reproduction steps

See the examples in the Expected Behavior section.

Additional Notes

No response

Log File

No response

@sumneko sumneko added the bug Something isn't working label Jan 30, 2023
sumneko added a commit that referenced this issue Jan 30, 2023
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

2 participants