luau icon indicating copy to clipboard operation
luau copied to clipboard

String literals don't properly narrow with `if cond or (literal == "")`

Open ffrostfall opened this issue 2 years ago • 1 comments
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.

ffrostfall avatar Jun 12 '23 17:06 ffrostfall

Tweaked the example to be more obviously a bug (as separateCond value is arbitrary)

zeux avatar Jun 12 '23 19:06 zeux