role R { }
role S does R { }
role T does S { }
my R $r0 = T; # compiles
my R $r1 = role U does R { }; # compiles
my R $r2 = role V does S { }; # compile error:
# Type check failed in assignment to $r2; expected R but got V (V)
Should the assignment to $r2 be possible?
The goal is to do something like:
my R @r = (
role W does S { ... },
# etc.
);
my %h = @r.map: { .^name => $_ };
Yes.
And I think you've found a bug.
It looks like a timing related issue. If you define the V role beforehand, there doesn't seem to be an issue:
role R { }
role S does R { }
role T does S { }
role V does S { }
my R $r0 = T; # compiles
my R $r1 = role U does R { }; # compiles
my R $r2 = V; # compiles
So at least as a temporary workaround, I'd suggest you define all the roles beforehand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With