Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
throw ex for usage of $foo before $^foo in sub body (RT #123470)
  • Loading branch information
FROGGS committed Dec 21, 2014
1 parent 08c2b0f commit 4569b17
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -2397,6 +2397,15 @@ class Perl6::Actions is HLL::Actions does STDActions {
[];
}
my @params := %sig_info<parameters>;
for @params -> {
if $block.ann('also_uses') && $block.ann('also_uses'){$_<variable_name>} {
$*W.throw($/, ['X', 'Placeholder', 'NonPlaceholder'],
placeholder => $_<placeholder>,
variable_name => $_<variable_name>,
decl => $*IN_DECL,
)
}
}
set_default_parameter_type(@params, 'Any');
my $signature := create_signature_object($<multisig> ?? $<multisig> !! $/, %sig_info, $block);
add_signature_binding_code($block, $signature, @params);
Expand Down
11 changes: 11 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -581,6 +581,17 @@ my class X::Placeholder::Block does X::Comp {
}
}

my class X::Placeholder::NonPlaceholder does X::Comp {
has $.variable_name;
has $.placeholder;
has $.decl;
method message() {
my $decl = $!decl ?? ' ' ~ $!decl !! '';
"$!variable_name has already been used as a non-placeholder in the surrounding$decl block,\n" ~
" so you will confuse the reader if you suddenly declare $!placeholder here"
}
}

my class X::Placeholder::Mainline is X::Placeholder::Block {
method message() {
"Cannot use placeholder parameter $.placeholder in the mainline"
Expand Down

0 comments on commit 4569b17

Please sign in to comment.