On Sat, 03 Jun 2017 21:20:49 -0700, c...@zoffix.com wrote: > (found in discussion in > https://rt.perl.org/Ticket/Display.html?id=131493 ) > > > We have some special casing for coercion of allomorphs in some > instances, which > is done so there'd be some way to force one of the two types to fall > out of it, > since we have types where to whom object identity matters a bunch: > > <Zoffix__> m: <1>.Str.^name.say > <camelia> rakudo-moar 7344a3: OUTPUT: «Str» > <Zoffix__> m: <1>.Int.^name.say > <camelia> rakudo-moar 3755c0: OUTPUT: «Int» > > However, allomorphs don't get coerced with parameter coercers and > possibly some > other places. There's no special casing here done. The coercer coerces > to Str type > and IntStr allomorph is already it. > > <Zoffix__> m: -> Str() $_ { .^name.say }(<1>) > <camelia> rakudo-moar 7344a3: OUTPUT: «IntStr» > <Zoffix__> m: -> Int() $_ { .^name.say }(<1>) > <camelia> rakudo-moar 7344a3: OUTPUT: «IntStr» > > > So the question becomes: do we special case allomorphs everywhere?
No. The current behavior seems correct to me. > - If yes, any place we special case them will have a caveat and > surprising behaviour > where type don't get coerced to exact asked type if it's a > subclass of it If you want something coerced to the exact type, this can be done outside of the signature. I would just document the behavior for coercions clearly, in that if the value already satisfy the type in the coercer, your value is passed through unchanged. > - If no, we get surprising special cased behaviour like above, but > only in one case > - Or we could remove the coercion to one of the two types and have > <1>.Str return the same > IntStr; in that case I'm unsure what would be a way to "collapse" > an allomorph into > numeric or string parts, since many ops use these methods to coerce > stuff. -- Will "Coke" Coleda