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

The type of keys used to index [] tables is not checked #2610

Open
mycroftjr opened this issue Apr 13, 2024 · 1 comment
Open

The type of keys used to index [] tables is not checked #2610

mycroftjr opened this issue Apr 13, 2024 · 1 comment

Comments

@mycroftjr
Copy link

mycroftjr commented Apr 13, 2024

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

Expected Behaviour

Some warning should be raised if you use [5] on a table<string, x>, for example.

Actual Behaviour

In the expression tbl[x], the type of x is not checked at all

Reproduction steps

---@type table<integer, string> -- or string[]
local IntStr = {}
---@type table<string, integer>
local StrInt = {}
IntStr[5] = "hi" -- ok
IntStr["a"] = "b" -- "a" should produce a warning
StrInt["a"] = 5 -- ok
StrInt[5] = 6 -- 5 should produce a warning

Additional Notes

Probably related to #1861

Log File

No response

@emmericp
Copy link
Contributor

+1 for supporting this, it is especially annoying if you have a table that is supposed to be indexed by an enum, e.g.,

---@type table<"foo"|"bar", number>
local foo

foo["wrong value"] = 5 -- should be an error

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

2 participants