Hi, I cannot wrap my head around below piece of code... What am I doing wrong?
https://carc.in/#/r/16r0
reduced
class Foo
@callback : Proc(Bool?)? = -> {}
end
Error in line 2: instance variable '@callback' of Foo must be (Proc((Bool | Nil)) | Nil), not Proc(Nil)
Right now, a proc that returns X isn't implicitly castable to a proc that returns X | Y.
In your case you have ->{}, which is Proc(Nil), but you require the callback to be Proc(Bool | Nil). It's solved if you do Proc(Bool?).new { } instead of ->{}.
I'm still not sure the rules should change. This works but maybe shouldn't:
def foo(block : -> Int32 | String)
end
foo ->{ 1 }