Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
throw a typed exception for non-conformant qualified method calls
  • Loading branch information
moritz committed May 27, 2012
1 parent 9452bf6 commit 50d40a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -51,6 +51,16 @@ my class X::Method::NotFound is Exception {
}
}

my class X::Method::InvalidQualifier is Exception {
has $.method;
has $.invocant;
has $.qualifier-type;
method message() {
"Cannot dispatch to method $.method on {$.qualifier-type.^name} "
~ "because it is no inhertied or done by {$.invocant.^name}";
}
}


sub EXCEPTION(|$) {
my Mu $parrot_ex := nqp::shift(pir::perl6_current_args_rpa__P());
Expand Down
10 changes: 7 additions & 3 deletions src/core/Mu.pm
@@ -1,5 +1,6 @@
my class X::Constructor::Positional { ... }
my class X::Method::NotFound { ... }
my class X::Method::InvalidQualifier { ... }

my class Mu {
proto method ACCEPTS(|$) { * }
Expand Down Expand Up @@ -257,9 +258,12 @@ my class Mu {

method dispatch:<::>(Mu \$self: $name, Mu $type, |$c) is rw {
unless nqp::istype($self, $type) {
die "Cannot dispatch to a method on " ~ $type.WHAT.perl ~
" because it is not inherited or done by " ~
$self.WHAT.perl;
X::Method::InvalidQualifier.new(
method => $name,
invocant => $self,
qualifier-type => $type,

).throw;
}
pir::find_method__PPS($type, $name)($self, |$c)
}
Expand Down

0 comments on commit 50d40a6

Please sign in to comment.