luau
luau copied to clipboard
String literals don't properly narrow with `if cond or (literal == "")`
trafficstars
local literal: "a" | "b"
local separateCond = ...
if separateCond or (literal == "a") then
if literal == "b" then -- Type error, "a" cannot be compared with "b"
print()
end
end
This shouldn't error, because literal isn't guaranteed to be "a", it could be "b" due to the separateCond condition in the if statement.
Tweaked the example to be more obviously a bug (as separateCond value is arbitrary)