Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
move X::Does::TypeObject to operators.pm
it reads much nicer to have the exception defined close to where it is thrown

Also record the type that was attempt to mix into
  • Loading branch information
moritz committed Feb 6, 2015
1 parent 8e91140 commit 7f20855
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/core/Exception.pm
Expand Up @@ -926,10 +926,6 @@ my class X::Syntax::Argument::MOPMacro does X::Syntax {
method message() { "Cannot give arguments to $.macro" };
}

my class X::Does::TypeObject is Exception {
method message() { "Cannot use 'does' operator with a type object." }
}

my class X::Role::Initialization is Exception {
has $.role;
method message() { "Can only supply an initialization value for a role if it has a single public attribute, but this is not the case for '{$.role.^name}'" }
Expand Down
9 changes: 7 additions & 2 deletions src/core/operators.pm
Expand Up @@ -7,6 +7,11 @@ sub infix:<=>(Mu \a, Mu \b) is rw {
nqp::p6store(a, b)
}

my class X::Does::TypeObject is Exception {
has Mu $.type;
method message() { "Cannot use 'does' operator with a type object." }
}

proto sub infix:<does>(Mu, Mu, *%) { * }
multi sub infix:<does>(Mu:D \obj, Mu:U \rolish) is rw {
# XXX Mutability check.
Expand All @@ -24,14 +29,14 @@ multi sub infix:<does>(Mu:D \obj, Mu:U \rolish, :$value! is parcel) is rw {
mixedin.BUILD_LEAST_DERIVED({ substr(mixedin.^mixin_attribute.Str,2) => $value });
}
multi sub infix:<does>(Mu:U \obj, Mu:U \role) is rw {
X::Does::TypeObject.new().throw
X::Does::TypeObject.new(type => obj).throw
}
multi sub infix:<does>(Mu:D \obj, @roles) is rw {
# XXX Mutability check.
obj.HOW.mixin(obj, |@roles).BUILD_LEAST_DERIVED({});
}
multi sub infix:<does>(Mu:U \obj, @roles) is rw {
X::Does::TypeObject.new().throw
X::Does::TypeObject.new(type => obj).throw
}

proto sub infix:<but>(Mu, Mu, *%) { * }
Expand Down

0 comments on commit 7f20855

Please sign in to comment.