Type CASTED unions don't refine correctly

--!strict

local c_array: {false | CFrame} = {false, CFrame.new(0, 0, 0), false, CFrame.new(0, 0, 0)}
local c = false :: CFrame | false
local y: CFrame | false = false
local z = c_array[1]

if z then
	
	z:ToObjectSpace(CFrame.new(0, 1, 2)) -- Type error since c is resolved as CFrame | true despite type refining to CFrame with the if statement
end

if c then

	c:ToObjectSpace(CFrame.new(0, 1, 2)) -- Also a type error
end

if y then

	y:ToObjectSpace(CFrame.new(0, 1, 2)) -- Succesfully type refines to CFrame
end

Expected behavior

vars c and z should be resolved as CFrame within the if statements

1 Like

This refinement works with the new type solver. Its Studio beta was planned for June and release for 2024 (Aaron in ROSS). Old solver is “pretty much in code freeze” (Alex McCord in ROSS).

I opened an issue for the only error in your code with the new solver, local c = false :: CFrame | false.

To access it early, you could use Luau-LSP and VS Code, setting DebugLuauDeferredConstraintResolution to true in luau-lsp.fflags.override. It’s too unstable for me to recommend just yet.

This is just an acknowledgment announcement!

We’ve filed a ticket into our internal database for this issue, and we will update you when we have further information!

Thanks for the report!