Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mark blocks like { .foo } as "$_ is used"
This fixes RT #125767
  • Loading branch information
FROGGS committed Aug 14, 2015
1 parent cee1a80 commit ab73b0a
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/Perl6/Grammar.nqp
Expand Up @@ -289,6 +289,22 @@ role STD {
self.typed_panic('X::Syntax::DuplicatedPrefix', :$prefixes);
}

method mark_variable_used($name) {
my $lex := $*W.cur_lexpad();
my %sym := $lex.symbol($name);
if %sym {
%sym<used> := 1;
}
else {
# Add mention-only record (used to poison outer
# usages and disambiguate hashes/blocks by use of
# $_ when $*IMPLICIT is in force).
my $au := $lex.ann('also_uses');
$lex.annotate('also_uses', $au := {}) unless $au;
$au{$name} := 1;
}
}

method check_variable($var) {
my $varast := $var.ast;
if nqp::istype($varast, QAST::Op) && $varast.op eq 'ifnull' {
Expand Down Expand Up @@ -323,19 +339,7 @@ role STD {
}
}
else {
my $lex := $*W.cur_lexpad();
my %sym := $lex.symbol($name);
if %sym {
%sym<used> := 1;
}
else {
# Add mention-only record (used to poison outer
# usages and disambiguate hashes/blocks by use of
# $_ when $*IMPLICIT is in force).
my $au := $lex.ann('also_uses');
$lex.annotate('also_uses', $au := {}) unless $au;
$au{$name} := 1;
}
self.mark_variable_used($name);
}
}
if !$*IN_DECL && nqp::istype($varast, QAST::Op) && $varast.name eq '&DYNAMIC' {
Expand Down Expand Up @@ -3150,7 +3154,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
]
}

token term:sym<dotty> { <dotty> }
token term:sym<dotty> { <dotty> { self.mark_variable_used('$_') } }

token term:sym<capterm> { <capterm> }

Expand Down

0 comments on commit ab73b0a

Please sign in to comment.