luau icon indicating copy to clipboard operation
luau copied to clipboard

`never` is not a subtype of generic packs, or packs with more than one value (new solver only)

Open Aseminaunz opened this issue 2 months ago • 0 comments

--!strict

local function unreachable(): never
	error("Unreachable")
end

local function myFuncA<T...>(...: T...): T...
	if math.random() > 0.5 then
		return ...
	else
		return unreachable()
	end
end

local function myFuncB(): (number, number)
	if math.random() > 0.5 then
		return 1, 2
	else
		return unreachable()
	end
end

return unreachable() type errors with

TypeError: Type pack 'T...' could not be converted into 'never, ...never'

on old solver, and

TypeError: Type pack 'never' could not be converted into 'T...'; this is because it has a tail of `T...`, and `never` is not a subtype of `T...`

TypeError: Type pack 'never' could not be converted into 'number, number'

on new solver.

myFuncB does not cause any type errors on old solver.

Expected behavior would be for never to be a subtype of a generic type pack or a pack with more than one value, as would be for a generic non-pack, or a non-generic pack. Neither of these error:

local function myFunc<T>(foo: T): T
	if math.random() > 0.5 then
		return foo
	else
		return unreachable()
	end
end

local function myFunc(foo: any): ...number
	if math.random() > 0.5 then
		return foo
	else
		return unreachable()
	end
end

Aseminaunz avatar Oct 08 '25 00:10 Aseminaunz