See https://forum.crystal-lang.org/t/splat-generics-with-proc/1410
class Foo(R, *A)
def initialize(@action : Proc(*A, R)); end
end
pp Foo(String, Int32, Bool).new ->(a : Int32, b : Bool) { "foo" }
Error:
Error: instance variable '@action' of Foo(String, Int32, Bool) must be Proc(*A, String), not Proc(Int32, Bool, String)
@asterite Do you have any pointers on where to look if I wanted to take a shot at this? My current guess is that the splat arguments need to be "expanded" before seeing if they match or not?
Update, this is also an issue when using splat generics as type restriction of a method within Union.
https://play.crystal-lang.org/#/r/85x2
class Foo(*Args)
def execute(value : Union(*Args))
pp value
end
end
foo = Foo(String, Int32).new
foo.execute 19
Showing last frame. Use --error-trace for full trace.
error in line 10
Error: no overload matches 'Foo(String, Int32)#execute' with type Int32
Overloads are:
- Foo(Args)#execute(value : Union(*Args))
I think the logic is in restrictions.cr but I'm not sure.
Most helpful comment
I think the logic is in restrictions.cr but I'm not sure.