Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Role-constrained variable does not accept derived role defined inline

Tags:

raku

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 => $_ };

like image 392
user1915829 Avatar asked Apr 29 '26 13:04

user1915829


1 Answers

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.

like image 69
Elizabeth Mattijsen Avatar answered May 05 '26 12:05

Elizabeth Mattijsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!