New solver: Type inference fails when passing a generic function to pcall (or variadic generic wrappers)

Environment:
Studio Version: 0.702.0.7020614 (64 bit) (channel: production)
OS: Windows 11, 64 bit

When passing a generic function directly to pcall (or any custom function that accepts a callback and type pack(variadic?) arguments for that callback), the Luau type checker fails to infer the generic type parameters based on the provided arguments.

Instead of inferring the generic type T from the arguments passed after the function, the type checker threats T as an incompatible rigid type, causing a false positive type error.

Reproduction Code:

-- Define a simple generic function
local function fn<T>(a: T): T
	return a
end

-- Attempt to call it via pcall with a concrete type (number)
-- Expected: T should be inferred as 'number'
-- Actual: Type error, Type 'number' could not be converted into 'T'
local ok, result = pcall(fn, 5)

Observed Behavior: The type checker emits the following error: Type 'number' could not be converted into 'T'
It seems like the type checker validates the function signature against pcall’s definition before instantiating the generic T with the value 5.

Expected behavior

The type checker should correctly infer that T is number based on the second argument (5) passed to pcall, similar to how it works when calling fn(5) directly

Workaround:
Wrapping the call in an anonymous closure resolves the error, but creates unnecessary runtime overhead (and closure allocation).

-- This works, but is verbose and less efficient
local ok, result = pcall(function() 
    return fn(5) 
end)
2 Likes

Thanks for the report! Someone on our team will look into this.

2 Likes

Hello! Thanks again for the report!

A fix for this should be available in 0.729.

2 Likes