Return OPERATOR('[') for '[' without falling through to case '~', avoiding misinterpr...
Ian Goodacre [Sat, 14 Mar 2009 06:04:12 +0000 (19:04 +1300)]
t/base/lex.t
toke.c

index f45e56c..9892df5 100755 (executable)
@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..56\n";
+print "1..57\n";
 
 $x = 'x';
 
@@ -267,3 +267,11 @@ foo::::::bar;
 eval "\$x =\xE2foo";
 if ($@ =~ /Unrecognized character \\xE2 in column 5/) { print "ok $test\n"; } else { print "not ok $test\n"; }
 $test++;
+
+# Is "[~" scanned correctly?
+eval '
+    my @a;
+    my $x = $a[~1]
+';
+print "not " if($@);
+print "ok 57\n";
diff --git a/toke.c b/toke.c
index 3c3e0ad..8f5795a 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -4287,7 +4287,10 @@ Perl_yylex(pTHX)
        BOop(OP_BIT_XOR);
     case '[':
        PL_lex_brackets++;
-       /* FALL THROUGH */
+       {
+           const char tmp = *s++;
+           OPERATOR(tmp);
+       }
     case '~':
        if (s[1] == '~'
            && (PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR))