Skip to content

Commit

Permalink
throw typed exception on illegal use of placeholder parameters
Browse files Browse the repository at this point in the history
also catches  class A { $^x }, which used to live errornously
  • Loading branch information
moritz committed Jan 23, 2012
1 parent 63663bd commit 3ddd2fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Perl6/Actions.pm
Expand Up @@ -620,7 +620,7 @@ class Perl6::Actions is HLL::Actions {
method block($/) {
my $block := $<blockoid>.ast;
if $block<placeholder_sig> {
$/.CURSOR.panic("Cannot use placeholder parameters in this kind of block");
$*W.throw($/, ['X', 'Placeholder', 'Block']);
}
($*W.cur_lexpad())[0].push(my $uninst := PAST::Stmts.new($block));
my $code := $*W.create_code_object($block, 'Block', $*W.create_signature([]));
Expand Down Expand Up @@ -1197,6 +1197,10 @@ class Perl6::Actions is HLL::Actions {
}
$block.blocktype('immediate');

if $*PKGDECL ne 'role' && $block<placeholder_sig> {
$*W.throw($/, ['X', 'Placeholder', 'Block']);
}

# If it's a stub, add it to the "must compose at some point" list,
# then just evaluate to the type object. Don't need to do any more
# just yet.
Expand Down
6 changes: 6 additions & 0 deletions src/core/Exceptions.pm
Expand Up @@ -50,6 +50,12 @@ my class X::Signature::Placeholder is X::Base does X::Comp {
}
}

my class X::Placeholder::Block is X::Base does X::Comp {
method message() {
'Cannot use placeholder parameters in this kind of block';
}
}

my class X::Attribute::Undeclared is X::Base does X::Comp {
has $.name;
has $.package-type;
Expand Down

0 comments on commit 3ddd2fb

Please sign in to comment.