Skip to content

@generic class incorrect type checking #1378

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
carsakiller opened this issue Jul 23, 2022 · 1 comment
Closed

@generic class incorrect type checking #1378

carsakiller opened this issue Jul 23, 2022 · 1 comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request feat/generic Related to generic emulation feature feat/type check Related to the type checking feature

Comments

@carsakiller
Copy link
Collaborator

carsakiller commented Jul 23, 2022

@generic seems to be behaving weirdly when being used in a class.

---@class Array<T>: { [integer]: T }

---@type Array<string>
local arr = {}

-- correctly warns that I am assigning a boolean to a string
arr[1] = false

-- no warning despite indexing with a string instead of an integer
arr["foo"] = "bar"

-- correctly does not warn as I am following the type correctly
arr[3] = "Correct"

Behaves even weirder for a dictionary:

---@class Dictionary<T>: { [string]: T }

---@type Dictionary<boolean>
local dict = {}

-- no warning despite indexing with a number
dict[1] = "incorrect"

-- no warning despite assigning a string
dict["foo"] = "bar?"

-- correctly does not warn as I am following the type correctly
dict["correct"] = true

The same issues exist when indexing with . like dict.foo = "bar?"

Originally posted by @carsakiller in #1362 (comment)

@sumneko sumneko added enhancement New feature or request feat/type check Related to the type checking feature feat/generic Related to generic emulation feature labels Jul 23, 2022
@carsakiller carsakiller changed the title @generic misbehaving when used with a class @generic class incorrect type checking Jan 30, 2023
@carsakiller carsakiller added the duplicate This issue or pull request already exists label Feb 20, 2023
@carsakiller
Copy link
Collaborator Author

Closing as duplicate of #734 as this is really just asking for generic class support.

@carsakiller carsakiller closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request feat/generic Related to generic emulation feature feat/type check Related to the type checking feature
Projects
None yet
Development

No branches or pull requests

2 participants