in reply to Type coercion and union
I think the problem is that the union type ends up with two different coercions both from "Str". When trying to coerce a string, it tries the first one, it fails, and then it says "welp; I guess I can't coerce from string then!"
The solution would be to not coerce from Str, but coerce from something more specific.
my %invoice_map = ( Invoice => 'ACCREC', SupplierInvoice => 'ACCPAY', ); coerce InvoiceType, from Enum[ keys %invoice_map ], via { return $invoice_map{$_} };
Now InvoiceType doesn't have a general coercion from Str, but just from the exact values it knows how to coerce.
|
|---|