Open Vici37 opened 1 year ago
Reduced:
def call(pr : Proc(Nil) | Proc(String))
end
call(->{ "" })
Error:
BUG: trying to downcast (Proc(Nil) | Proc(String)) (Crystal::MixedUnionType) <- Proc(String) (Crystal::ProcInstanceType) (Exception)
I guess the implicit casting of Proc(T)
to Proc(Nil)
is happening here somehow.
I won't fix this because I think first we should disallow such casting. It's wrong and it has a wrong codegen semantic.
This may be related to #12472 but I wasn't positive, so I'm creating a new bug report just in case.
Below causes a compiler bug error:
Which causes the error:
For my use case, I was trying to create a list of procs that would accept an argument and return a String, nil, or undetermined between those two. Using the naive
Proc(String, String?)
kept throwing errors when I constructed a proc that guaranteed only returned String or nil, so expanded the union as needed, and here we are :)