This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #123737] delay reporting a missing operator for arrays
authorTony Cook <tony@develop-help.com>
Sun, 10 Jan 2016 23:42:31 +0000 (10:42 +1100)
committerTony Cook <tony@develop-help.com>
Sun, 10 Jan 2016 23:42:31 +0000 (10:42 +1100)
Previously it was reported at the beginning of the '@' case, without
even skipping the @ symbol.

Make the code more similar to the scalar case and try to parse an
identifier first.

t/lib/croak/toke
toke.c

index 64012fb..50394da 100644 (file)
@@ -37,6 +37,15 @@ syntax error at - line 1, near "0$#"
 Missing right curly or square bracket at - line 1, at end of line
 Execution of - aborted due to compilation errors.
 ########
+# NAME (Missing opertaor before @foo) [perl #123737]
+0@foo
+EXPECT
+Array found where operator expected at - line 1, near "0@foo"
+       (Missing operator before @foo?)
+syntax error at - line 1, near "0@foo
+"
+Execution of - aborted due to compilation errors.
+########
 # NAME Unterminated here-doc in string eval
 eval "<<foo"; die $@
 EXPECT
diff --git a/toke.c b/toke.c
index 7f45f1b..95ce3fd 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -6364,11 +6364,12 @@ Perl_yylex(pTHX)
        TOKEN('$');
 
     case '@':
-       if (PL_expect == XOPERATOR)
-           no_op("Array", s);
-       else if (PL_expect == XPOSTDEREF) POSTDEREF('@');
+        if (PL_expect == XPOSTDEREF)
+            POSTDEREF('@');
        PL_tokenbuf[0] = '@';
        s = scan_ident(s, PL_tokenbuf + 1, sizeof PL_tokenbuf - 1, FALSE);
+       if (PL_expect == XOPERATOR)
+           no_op("Array", s);
        pl_yylval.ival = 0;
        if (!PL_tokenbuf[1]) {
            PREREF('@');