Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

warn on for with single scalar variable

  • Loading branch information...
commit c2215f042bf75ed1c592467bd65f837382dcaf94 1 parent 85cf51d
@TimToady TimToady authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 STD.pm6
View
13 STD.pm6
@@ -1542,6 +1542,17 @@ grammar P6 is STD {
[ <?before '(' <.EXPR>? ';' <.EXPR>? ';' <.EXPR>? ')' >
<.obs('C-style "for (;;)" loop', '"loop (;;)"')> ]?
<xblock>
+ <.worry_itemlist($<xblock><EXPR>)>
+ }
+
+ method worry_itemlist($expr) {
+ if $expr<variable> {
+ my $var = $expr<variable>.Str;
+ if substr($var,0,1) eq '$' {
+ self.cursor($expr.from).worry("'for $var' will never flatten a \$ variable;\n\tto force list interpolation, please use either 'for \@$var' or 'for $var\[]';\n\tif you just want item topicalization, use 'given $var' instead");
+ }
+ }
+ self;
}
rule statement_control:given {
@@ -1590,7 +1601,7 @@ grammar P6 is STD {
rule statement_mod_loop:while {<sym> <modifier_expr> }
rule statement_mod_loop:until {<sym> <modifier_expr> }
- rule statement_mod_loop:for {<sym> <modifier_expr> }
+ rule statement_mod_loop:for {<sym> <modifier_expr> <.worry_itemlist($<modifier_expr><EXPR>)> }
rule statement_mod_loop:given {<sym> <modifier_expr> }
################
Please sign in to comment.
Something went wrong with that request. Please try again.