luau icon indicating copy to clipboard operation
luau copied to clipboard

[New Solver] Type Solver encounters an unexpected type pack in subtyping when using returned values from a function with generic type packs.

Open TenebrisNoctua opened this issue 3 months ago • 1 comments

When iterating over a table, and setting the metatable of a value with pcall, and using the returned values from this pcall operation, a type error occurs.

local foo: {any} = {}
for key, value in foo do
	local success, result = pcall(setmetatable, value, {}) -- Encountered an unexpected type pack in subtyping: a...
end

This type error does not happen when you don't use the returned values from the pcall:

local foo: {any} = {}
for key, value in foo do
	pcall(setmetatable, value, {}) -- No type error.
end

TenebrisNoctua avatar Sep 27 '25 17:09 TenebrisNoctua

This is happening for all functions that have a generic pack for parameters and return values:

function example<P..., R...>(func: (P...) -> (R...), ...: P...): R...
	--return func(...)
end

function test(a: number, b: number): (string, string)
	return "epic", "strings"
end

local result1, result2 = example(test, 1, 2) --Encountered an unexpected type pack in subtyping: a...

It doesn't happen when only one of these is used:

function example<P..., R...>(func: (P...) -> (R...)): R...
	--return func(...)
end

function test(a: number, b: number): (string, string)
	return "epic", "strings"
end

local result1, result2 = example(test) --No error, but parameters aren't typed
function example<P..., R...>(func: (P...) -> (R...), ...: P...)
	--return func(...)
end

function test(a: number, b: number): (string, string)
	return "epic", "strings"
end

example(test, 1, 2) --No error, but return values aren't typed

JokeCommit avatar Sep 28 '25 04:09 JokeCommit