Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
warn about variables in sink context
  • Loading branch information
moritz committed Feb 18, 2013
1 parent b9ee89a commit 018b73b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Perl6/Actions.pm
Expand Up @@ -1322,6 +1322,9 @@ class Perl6::Actions is HLL::Actions does STDActions {
$past := make_variable($/, [~$/]);
}
}
if $*IN_DECL eq 'variable' {
$past<sink_ok> := 1;
}
make $past;
}

Expand Down
13 changes: 11 additions & 2 deletions src/Perl6/Optimizer.pm
Expand Up @@ -489,7 +489,16 @@ class Perl6::Optimizer {

# Handles visit a variable node.
method visit_var($var) {
# Nothing to do yet.
if $*VOID_CONTEXT && !$*IN_DECLARATION && $var.name && !$var<sink_ok> {
# stuff like Nil is also stored in a QAST::Var, but
# we certainly don't want to warn about that one.
my str $sigil := nqp::substr($var.name, 0, 1);
if $sigil eq '$' || $sigil eq '@' || $sigil eq '%' {
self.add_worry($var, "Useless use of variable " ~ $var.name ~ " in sink context");
return $NULL;
}
}
$var;
}

# Checks arguments to see if we're going to be able to do compile
Expand Down Expand Up @@ -598,7 +607,7 @@ class Perl6::Optimizer {
$node[$i] := self.visit_want($visit);
}
elsif nqp::istype($visit, QAST::Var) {
self.visit_var($visit);
$node[$i] := self.visit_var($visit);
}
elsif nqp::istype($visit, QAST::Block) {
$node[$i] := self.visit_block($visit);
Expand Down

0 comments on commit 018b73b

Please sign in to comment.