Skip to content

[fix/type-checking] ternary operator incorrect type infer #3154

Closed as duplicate of#2233
@AgatZan

Description

@AgatZan

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Windows

What is the issue affecting?

Type Checking, Annotations

Expected Behaviour

TO BE

code 1

---@type string|string[]
local x = ""

-- TO BE xs: string[] 
-- AS IS xs: string[] | string
local xs = type(a) == "string" and {x} or x

if type(x) == "string" then
  xs = {x}
else
  xs = a
end
-- but xs:string[]

Actual Behaviour

AS IS

Reproduction steps

  1. Create file temp.lua
  2. Append code 1
  3. See type of xs

Additional Notes

No response

Log File

Log file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions