develooper Front page | perl.perl5.changes | Postings from January 2019

[perl.git] branch blead updated. v5.29.7-14-g5d4636a3aa

From:
Tony Cook
Date:
January 22, 2019 00:24
Subject:
[perl.git] branch blead updated. v5.29.7-14-g5d4636a3aa
Message ID:
E1gljrq-0001CL-VM@git.dc.perl.space
In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/5d4636a3aa0bc51a92e8f239caafb9c4539ab28f?hp=de6852e1f88363cd1f464aea12d73232a18c25a5>

- Log -----------------------------------------------------------------
commit 5d4636a3aa0bc51a92e8f239caafb9c4539ab28f
Author: Tony Cook <tony@develop-help.com>
Date:   Mon Dec 19 10:49:27 2016 +1100

    (perl #130367) separate error for push etc on hash/glob

-----------------------------------------------------------------------

Summary of changes:
 op.c           |  4 ++++
 t/lib/croak/op | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/op.c b/op.c
index 0b46b348cb..39006ad1cb 100644
--- a/op.c
+++ b/op.c
@@ -11688,6 +11688,10 @@ Perl_ck_fun(pTHX_ OP *o)
 		         || SvTYPE(SvRV(cSVOPx_sv(kid))) != SVt_PVAV  )
 		        )
 		    bad_type_pv(numargs, "array", o, kid);
+                else if (kid->op_type == OP_RV2HV || kid->op_type == OP_PADHV
+                         || kid->op_type == OP_RV2GV) {
+                    bad_type_pv(1, "array", o, kid);
+                }
 		else if (kid->op_type != OP_RV2AV && kid->op_type != OP_PADAV) {
                     yyerror_pv(Perl_form(aTHX_ "Experimental %s on scalar is now forbidden",
                                          PL_op_desc[type]), 0);
diff --git a/t/lib/croak/op b/t/lib/croak/op
index c11803e306..5f31478860 100644
--- a/t/lib/croak/op
+++ b/t/lib/croak/op
@@ -217,3 +217,37 @@ Execution of - aborted due to compilation errors.
 EXPECT
 Type of arg 1 to each must be hash or array (not constant item) at - line 1, near "FRED ;"
 Execution of - aborted due to compilation errors.
+########
+# NAME better messages for array-ops on non-arrays
+push %a, 1;
+pop %a;
+shift %a;
+unshift %a, 1;
+push *a, 1;
+pop *a;
+shift *a;
+unshift *a, 1;
+EXPECT
+Type of arg 1 to push must be array (not hash dereference) at - line 1, near "1;"
+Type of arg 1 to pop must be array (not hash dereference) at - line 2, near "%a;"
+Type of arg 1 to shift must be array (not hash dereference) at - line 3, near "%a;"
+Type of arg 1 to unshift must be array (not hash dereference) at - line 4, near "1;"
+Type of arg 1 to push must be array (not ref-to-glob cast) at - line 5, near "1;"
+Type of arg 1 to pop must be array (not ref-to-glob cast) at - line 6, near "*a;"
+Type of arg 1 to shift must be array (not ref-to-glob cast) at - line 7, near "*a;"
+Type of arg 1 to unshift must be array (not ref-to-glob cast) at - line 8, near "1;"
+Execution of - aborted due to compilation errors.
+########
+# NAME better messages for array-ops on non-arrays (part 2)
+# to check PADHV without hitting the reported error limit
+my %a;
+push %a, 1;
+pop %a;
+shift %a;
+unshift %a, 1;
+EXPECT
+Type of arg 1 to push must be array (not private hash) at - line 3, near "1;"
+Type of arg 1 to pop must be array (not private hash) at - line 4, near "%a;"
+Type of arg 1 to shift must be array (not private hash) at - line 5, near "%a;"
+Type of arg 1 to unshift must be array (not private hash) at - line 6, near "1;"
+Execution of - aborted due to compilation errors.

-- 
Perl5 Master Repository



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About