This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t use yyerror for each($scalar) experiment err
authorFather Chrysostomos <sprout@cpan.org>
Fri, 3 Jun 2016 05:10:04 +0000 (22:10 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 3 Jun 2016 05:37:36 +0000 (22:37 -0700)
This is a follow-up to 69e7f50e50.  69e7f50e50 resulted in yyerror
being called twice for the same error, resulting in double diagnos-
tics for where the error occurred:

$ ./perl -e 'keys $scalar, $1'
Experimental keys on scalar is now forbidden at -e line 1, near "$scalar,"
Type of arg 1 to keys must be hash or array (not scalar dereference) at -e line 1, near "$scalar,"
Execution of -e aborted due to compilation errors.

We don’t need ‘near "$scalar,"’ twice.

For the first one we should queue the error directly, using qerror()
(which yyerror itself normally calls), so we don’t get double
diagnostics.

op.c
t/op/smartkve.t

diff --git a/op.c b/op.c
index 90258f2..128cdc4 100644 (file)
--- a/op.c
+++ b/op.c
@@ -11968,9 +11968,9 @@ Perl_ck_each(pTHX_ OP *o)
                   )
                    goto bad;
            default:
-                yyerror_pv(Perl_form(aTHX_
+                qerror(Perl_mess(aTHX_
                     "Experimental %s on scalar is now forbidden",
-                     PL_op_desc[orig_type]), 0);
+                     PL_op_desc[orig_type]));
                bad:
                 bad_type_pv(1, "hash or array", o, kid);
                 return o;
index f092a8c..b947d0a 100644 (file)
@@ -19,8 +19,9 @@ sub set_errpat {
     # yyerror for the error, rather than croak.  yyerror is preferable for
     # compile-time errors.
     $errpat =
-       qr/Experimental $_[0] on scalar is now forbidden .* line 1,(?x:
-         ).*Type of arg 1 to $_[0] must be hash or array \(not /s;
+       qr/Experimental $_[0] on scalar is now forbidden .* line 1\.(?x:
+         ).*Type of arg 1 to $_[0] must be hash or array \(not (?x:
+         ).*line 1,/s;
 }
 
 # Keys -- errors