Skip to content

Type diagnostics fail on union types of Class|Class[]  #1871

Closed
@ttytm

Description

@ttytm

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Type Checking

Expected Behaviour

no warnings when annotating a union type of ---@param some_param Class|Class[]

---@class SomeClass
---@field [1] string
-- ...

---@param some_param SomeClass|SomeClass[]
local function some_fn(some_param) return end -- pretend to do some work

-- both should be valid
some_fn { { "test" } }
some_fn { "test" }

Actual Behaviour

---@class SomeClass
---@field [1] string
-- ...

---@param some_param SomeClass|SomeClass[]
local function some_fn(some_param) return end

some_fn { { "test" } } -- <- diagnostic: "Cannot assign `table` to `string`."
some_fn { "test" } -- <- this is valid.

array-only is valid:

---@param some_param SomeClass[]
local function some_fn(some_param) return end

some_fn { {"test"} } -- <- this is valid.

without using a class it is valid and correctly type checked:

---@param some_param {[1]: string}|{[1]: string}[]
local function some_fn(some_param) return some_param end
some_fn { "test" }
some_fn { { "test" } }

Reproduction steps

try the code above while having it checked with sumenko lua

Additional Notes

No response

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeat/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