Skip to content

Commit

Permalink
Make infix:<does> and X::Does::TypeObject also take nameds
Browse files Browse the repository at this point in the history
This makes the error more useful: before it could die because nameds
were not accepted by infix:<does>, which sent me on a goose chase for
an hour.  With the nameds shown, it became very clear what my problem was.
  • Loading branch information
lizmat committed Jan 14, 2018
1 parent f8953ee commit ddbf07e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/operators.pm
Expand Up @@ -9,7 +9,11 @@ sub infix:<=>(Mu \a, Mu \b) is raw {

my class X::Does::TypeObject is Exception {
has Mu $.type;
method message() { "Cannot use 'does' operator with a type object." }
has %.nameds;
method message() {
"Cannot use 'does' operator on a type object {$!type.^name}."
~ ("\nAdditional named parameters: {%!nameds.perl}." if %!nameds)
}
}

proto sub infix:<does>(|) {*}
Expand All @@ -28,8 +32,8 @@ multi sub infix:<does>(Mu:D \obj, Mu:U \rolish, :$value! is raw) is raw {
my \mixedin = obj.^mixin($role, :need-mixin-attribute);
mixedin.BUILD_LEAST_DERIVED({ substr(mixedin.^mixin_attribute.Str,2) => $value });
}
multi sub infix:<does>(Mu:U \obj, Mu:U \role) is raw {
X::Does::TypeObject.new(type => obj).throw
multi sub infix:<does>(Mu:U \obj, Mu:U \role, *%_) is raw {
X::Does::TypeObject.new(type => obj, nameds => %_).throw
}
multi sub infix:<does>(Mu:D \obj, **@roles) is raw {
# XXX Mutability check.
Expand Down

0 comments on commit ddbf07e

Please sign in to comment.