luau
luau copied to clipboard
New solver: Can't seem to accept function of arbitrary return type
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...`
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?
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...`
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)
Another:
type X<T...> = {
value: () -> T...,
}
local function f<T...>(x: X<T...>) end
local function g(x: X<string, number>)
f(x)
end