luau icon indicating copy to clipboard operation
luau copied to clipboard

New solver: Can't seem to accept function of arbitrary return type

Open Kampfkarren opened this issue 2 months ago • 4 comments

local function f<Return...>(callback: () -> Return...) end

f(print)

gives:

TypeError: Type
	'<T...>(T...) -> ()'
could not be converted into
	'() -> (Return...)'; 
this is because it returns `()` and it returns a tail of `Return...`, and `()` is not a subtype of `Return...`

Kampfkarren avatar Nov 04 '25 05:11 Kampfkarren

Seems like this is specifically the empty type pack not matching against a generic type pack? what about with a function that does return something?

aatxe avatar Nov 04 '25 05:11 aatxe

f(function()
	return 3
end)

...gives:

TypeError: Type
	'(...any) -> number'
could not be converted into
	'() -> (Return...)'; 
this is because it returns the portion of the type pack starting at index 0 to the end`number` and it returns a tail of `Return...`, and `number` is not a subtype of `Return...`

Kampfkarren avatar Nov 04 '25 05:11 Kampfkarren

Similar bug with this:

local function f<Rest...>(callback: (x: string, Rest...) -> any) end
f(error)
TypeError: Type
	'<T>(T, number?) -> never'
could not be converted into
	'(string, Rest...) -> any'; 
this is because it takes the portion of the type pack starting at index 1 to the end`number?` and it takes a tail of `Rest...`, and `number?` is not a supertype of `Rest...`Luau[1000](https://luau-lang.org/typecheck)

Kampfkarren avatar Nov 04 '25 05:11 Kampfkarren

Another:

type X<T...> = {
    value: () -> T...,
}

local function f<T...>(x: X<T...>) end

local function g(x: X<string, number>)
    f(x)
end

Kampfkarren avatar Nov 04 '25 06:11 Kampfkarren