Skip to content

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

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

Closed
AgatZan opened this issue Apr 13, 2025 · 1 comment
Closed

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

AgatZan opened this issue Apr 13, 2025 · 1 comment

Comments

@AgatZan
Copy link

AgatZan commented Apr 13, 2025

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

@AgatZan AgatZan changed the title ternary operator incorrect type infer [fix/type-checking] ternary operator incorrect type infer Apr 13, 2025
@tomlau10
Copy link
Contributor

I believe this is a duplicate of #2233, where the type narrow is not working correctly in ternary operator.

@AgatZan AgatZan closed this as completed Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants