Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When mixing in an enumeration and supplying an initialization value, …
…we should also apply coercion if needed, so day(2) works as well as day(tue).
  • Loading branch information
jnthn committed May 13, 2012
1 parent 32b1731 commit 9c85a3b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/operators.pm
Expand Up @@ -50,7 +50,13 @@ multi infix:<but>(Mu:D \$obj, Mu:U \$rolish, :$value! is parcel) {
my @attrs = $role.^attributes().grep: { .has_accessor };
die(X::Role::Initialization.new())
unless @attrs == 1;
$obj.HOW.mixin($obj.clone(), $role).BUILD_LEAST_DERIVED({ @attrs[0].Str.substr(2) => $value });
my $mixin-value := $value;
unless nqp::istype($value, @attrs[0].type) {
if @attrs[0].type.HOW.HOW.name(@attrs[0].type.HOW) eq 'Perl6::Metamodel::EnumHOW' {
$mixin-value := @attrs[0].type.($value);
}
}
$obj.HOW.mixin($obj.clone(), $role).BUILD_LEAST_DERIVED({ @attrs[0].Str.substr(2) => $mixin-value });
}
multi infix:<but>(Mu:U \$obj, Mu:U \$rolish) {
my $role := $rolish.HOW.archetypes.composable() ?? $rolish !!
Expand Down

0 comments on commit 9c85a3b

Please sign in to comment.