Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Typed exception for assigning to ro native param.
  • Loading branch information
jnthn committed Feb 24, 2015
1 parent 9276140 commit bea708f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Perl6/Actions.nqp
Expand Up @@ -5239,8 +5239,8 @@ class Perl6::Actions is HLL::Actions does STDActions {
# rather than at runtime since we'll innevitably fail.
my $scope := $lhs_ast.scope;
if $scope ne 'lexicalref' && $scope ne 'attributeref' {
# XXX Typed exception, only sorry?
$/.CURSOR.panic('Cannot assign to a readonly variable');
$lhs_ast.node.CURSOR.typed_sorry('X::Assignment::RO::Comp',
variable => $lhs_ast.name);
}
$past := QAST::Op.new(
:op(@native_assign_ops[$spec]), :returns($lhs_ast.returns),
Expand Down
7 changes: 7 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -1337,6 +1337,13 @@ my class X::Assignment::RO is Exception {
}
}

my class X::Assignment::RO::Comp does X::Comp {
has $.variable;
method message {
"Cannot assign to readonly variable {$.variable}"
}
}

my class X::Immutable is Exception {
has $.typename;
has $.method;
Expand Down

0 comments on commit bea708f

Please sign in to comment.