luau icon indicating copy to clipboard operation
luau copied to clipboard

Inference incorrect for intersection types involving unions with new solver

Open Ketasaja opened this issue 1 year ago • 0 comments

Tested on 0.636 with no errors in non-strict mode.

--!strict
type x = {
	x: number,
}
type y = x & {
	y: number?,
}

local _u: y = {
	x = 0,
	y = 0,
} --[[ TypeError: Type
'{ x: number, y: number }'
could not be converted into
'x & { y: number? }'; type { x: number, y: number }[read "y"] (number) is not exactly x & { y: number? }[1][read "y"][1] (nil)
]]

local _v: y = {
	x = 0,
	y = 0 :: number?,
}

local _w: y = {
	x = 0,
	y = 0,
} :: y

Ketasaja avatar Jul 28 '24 19:07 Ketasaja