Skip to content

False assign-type-mismatch for implicit integer keys with inherited class #960

@joshua-cooper

Description

@joshua-cooper

When a class inherits from another class and defines @field [integer] string, assigning a table with implicit integer keys (e.g. { "hello" }) produces a assign-type-mismatch warning. Using explicit keys ({ [1] = "hello" }) or removing the inheritance both avoid the warning.

Reproduction:

---@class OptsBase
---@field foo? boolean

---@class Opts : OptsBase
---@field [integer] string

---@type Opts
local opts1 = { "hello" } -- Warning: Cannot assign `("hello")` to `Opts`.  [assign-type-mismatch]

---@type Opts
local opts2 = { [1] = "hello" } -- No warning

Version: emmylua_ls 0.20.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions