From: Gurusamy Sarathy Date: Sun, 23 Jan 2000 06:43:51 +0000 (+0000) Subject: fix scope cleanup when next jumps to a continue block; this is rather X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1ee987245c095afd177d3e2ca6255cec8dbb53ca;p=p5sagit%2Fp5-mst-13.2.git fix scope cleanup when next jumps to a continue block; this is rather in the nature of a kludge; it doesn't fix the longstanding bug that makes C print "7" instead of "1") p4raw-id: //depot/perl@4848 --- diff --git a/pp_ctl.c b/pp_ctl.c index af8b947..af31a1c 100644 --- 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) diff --git a/t/cmd/while.t b/t/cmd/while.t index 392c137..515a7b6 100755 --- a/t/cmd/while.t +++ b/t/cmd/while.t @@ -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"; + } +}