Navigation Menu

Skip to content

Commit

Permalink
typed exceptions for errors from has_self branch
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Feb 11, 2012
1 parent 20cae50 commit 1733c1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Perl6/Actions.pm
Expand Up @@ -1094,7 +1094,7 @@ class Perl6::Actions is HLL::Actions {
# In a declaration, don't produce anything here.
if $*IN_DECL ne 'variable' {
unless $*HAS_SELF {
$/.CURSOR.panic("Variable $name used where no 'self' is available");
$*W.throw($/, ['X', 'Syntax', 'NoSelf'], variable => $name);
}
my $attr := get_attribute_meta_object($/, $name);
$past.scope('attribute_6model');
Expand All @@ -1106,9 +1106,9 @@ class Perl6::Actions is HLL::Actions {
}
elsif $twigil eq '.' && $*IN_DECL ne 'variable' {
if !$*HAS_SELF {
$/.CURSOR.panic("Variable $name used where no 'self' available");
$*W.throw($/, ['X', 'Syntax', 'NoSelf'], variable => $name);
} elsif $*HAS_SELF eq 'partial' {
$/.CURSOR.panic("Virtual call $name may not be used on partially constructed objects");
$*W.throw($/, ['X', 'Syntax', 'VirtualCall'], call => $name);
}
# Need to transform this to a method call.
$past := $<arglist> ?? $<arglist>[0].ast !! PAST::Op.new();
Expand Down
8 changes: 8 additions & 0 deletions src/core/Exceptions.pm
Expand Up @@ -249,3 +249,11 @@ my class X::Syntax::SigilWithoutName does X::Syntax {
my class X::Syntax::Self::WithoutObject does X::Syntax {
method message() { "'self' used where no object is available" }
}
my class X::Syntax::VirtualCall does X::Syntax {
has $.call;
method message() { "Virtual call $.call may not be used on partially constructed objects" }
}
my class X::Syntax::NoSelf does X::Syntax {
has $.variable;
method message() { "Variable $.variable used where no 'self' is available" }
}

0 comments on commit 1733c1f

Please sign in to comment.