Skip to content

Commit

Permalink
typed exceptions for some private method call fails
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jan 24, 2012
1 parent 2042efb commit 7d0453e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Perl6/Actions.pm
Expand Up @@ -2448,7 +2448,7 @@ class Perl6::Actions is HLL::Actions {
}
elsif $<value> {
if pir::exists(%*PARAM_INFO, 'nominal_type') {
$/.CURSOR.panic('Parameter may only have one prefix type constraint');
$*W.throw($/, ['X', 'Parameter', 'TypeConstraint']);
}
my $ast := $<value>.ast;
unless $ast<has_compile_time_value> {
Expand Down Expand Up @@ -2681,16 +2681,19 @@ class Perl6::Actions is HLL::Actions {
if @parts {
my $methpkg := $*W.find_symbol(@parts);
unless $methpkg.HOW.is_trusted($methpkg, $*PACKAGE) {
$/.CURSOR.panic("Cannot call private method '$name' on package " ~
$methpkg.HOW.name($methpkg) ~ " because it does not trust " ~
$*PACKAGE.HOW.name($*PACKAGE));
$*W.throw($/, ['X', 'Method', 'Private', 'Permission'],
:method( p6box_s($name)),
:source-package( p6box_s($methpkg.HOW.name($methpkg))),
:calling-package(p6box_s( $*PACKAGE.HOW.name($*PACKAGE))),
);
}
$past[1].type($methpkg);
}
else {
unless pir::can($*PACKAGE.HOW, 'find_private_method') {
$/.CURSOR.panic("Private method call to '$name' must be fully " ~
"qualified with the package containing the method");
$*W.throw($/, ['X', 'Method', 'Private', 'Qualified'],
:method(p6box_s($name)),
);
}
$past.unshift($*W.get_ref($*PACKAGE));
$past[0].type($*PACKAGE);
Expand Down
16 changes: 16 additions & 0 deletions src/core/Exceptions.pm
Expand Up @@ -128,3 +128,19 @@ my class X::Signature::NameClash does X::Comp {
"Name $.name used for more than one named parameter";
}
}

my class X::Method::Private::Permission does X::Comp {
has $.method;
has $.source-package;
has $.calling-package;
method message() {
"Cannot call private method '$.method' on package $.source-package because it does not trust $.calling-package";
}
}

my class X::Method::Private::Qualified does X::Comp {
has $.method;
method message() {
"Private method call to $.method must be fully qualified with the package containing the method";
}
}

0 comments on commit 7d0453e

Please sign in to comment.