fix scope cleanup when next jumps to a continue block; this is rather
authorGurusamy Sarathy <gsar@cpan.org>
Sun, 23 Jan 2000 06:43:51 +0000 (06:43 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Sun, 23 Jan 2000 06:43:51 +0000 (06:43 +0000)
in the nature of a kludge; it doesn't fix the longstanding bug that
makes C<while (!$x++) { local $x = 7 } continue { print $x }> print "7"
instead of "1")

p4raw-id: //depot/perl@4848

pp_ctl.c
t/cmd/while.t

index af8b947..af31a1c 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1960,9 +1960,15 @@ PP(pp_next)
        dounwind(cxix);
 
     TOPBLOCK(cx);
-    oldsave = PL_scopestack[PL_scopestack_ix - 1];
-    LEAVE_SCOPE(oldsave);
-    return cx->blk_loop.next_op;
+    {
+       OP *nextop = cx->blk_loop.next_op;
+       /* clean scope, but only if there's no continue block */
+       if (nextop == cUNOPx(cx->blk_loop.last_op)->op_first->op_next) {
+           oldsave = PL_scopestack[PL_scopestack_ix - 1];
+           LEAVE_SCOPE(oldsave);
+       }
+       return nextop;
+    }
 }
 
 PP(pp_redo)
index 392c137..515a7b6 100755 (executable)
@@ -2,7 +2,7 @@
 
 # $RCSfile: while.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:15 $
 
-print "1..15\n";
+print "1..17\n";
 
 open (tmp,'>Cmd_while.tmp') || die "Can't create Cmd_while.tmp.";
 print tmp "tvi925\n";
@@ -128,3 +128,16 @@ while (1) {
 $i++;
 print "not " unless $` . $& . $' eq "abc";
 print "ok $i\n";
+
+# check that scope cleanup happens right when there's a continue block
+{
+    my $var = 16;
+    while (my $i = ++$var) {
+       next if $i == 17;
+       last if $i > 17;
+       my $i = 0;
+    }
+    continue {
+        print "ok ", $var-1, "\nok $i\n";
+    }
+}