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

@generic class incorrect type checking #1378

Closed as not planned
Closed as not planned

Description

@carsakiller

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

Activity

  1. added
    enhancementNew feature or request
    feat/type checkRelated to the type checking feature
    feat/genericRelated to generic emulation feature
    on Jul 23, 2022
  2. changed the title [-]`@generic` misbehaving when used with a class[/-] [+]`@generic` class incorrect type checking[/+] on Jan 30, 2023
  3. carsakiller commented on Feb 20, 2023

    @carsakiller
    CollaboratorAuthor

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

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 existsenhancementNew feature or requestfeat/genericRelated to generic emulation featurefeat/type checkRelated to the type checking feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions