This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
only set CXp_FOR_DEF with CXp_FOR_GV
[perl5.git] / pp_ctl.c
index 735969c..3643ec5 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1458,7 +1458,7 @@ S_dopoptoloop(pTHX_ I32 startingblock)
     return i;
 }
 
-/* find the next GIVEN or FOR loop context block */
+/* find the next GIVEN or FOR (with implicit $_) loop context block */
 
 STATIC I32
 S_dopoptogivenfor(pTHX_ I32 startingblock)
@@ -2126,6 +2126,8 @@ PP(pp_enteriter)
             itersave = GvSV(sv);
             SvREFCNT_inc_simple_void(itersave);
             cxflags = CXp_FOR_GV;
+            if (PL_op->op_private & OPpITER_DEF)
+                cxflags |= CXp_FOR_DEF;
         }
         else {                          /* LV ref: for \$foo (...) */
             assert(SvTYPE(sv) == SVt_PVMG);
@@ -2135,9 +2137,8 @@ PP(pp_enteriter)
             cxflags = CXp_FOR_LVREF;
         }
     }
-
-    if (PL_op->op_private & OPpITER_DEF)
-       cxflags |= CXp_FOR_DEF;
+    /* OPpITER_DEF (implicit $_) should only occur with a GV iter var */
+    assert((cxflags & CXp_FOR_GV) || !(PL_op->op_private & OPpITER_DEF));
 
     PUSHBLOCK(cx, cxflags, MARK);
     PUSHLOOP_FOR(cx, itervarp, itersave);
@@ -2796,7 +2797,7 @@ PP(pp_goto)
                SP += items;
                if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx)) {
                    /* Restore old @_ */
-                    POP_SAVEARRAY();
+                    POP_SAVEARRAY(cx);
                }
 
                retop = cx->blk_sub.retop;