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

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

Closed
ttytm opened this issue Feb 1, 2023 · 0 comments
Closed

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

ttytm opened this issue Feb 1, 2023 · 0 comments
Labels
bug Something isn't working feat/type check Related to the type checking feature

Comments

@ttytm
Copy link

ttytm commented Feb 1, 2023

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

@sumneko sumneko added bug Something isn't working feat/type check Related to the type checking feature labels Feb 2, 2023
@sumneko sumneko closed this as completed in 36ed61d Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat/type check Related to the type checking feature
Projects
None yet
Development

No branches or pull requests

2 participants