summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_ctl.c12
-rwxr-xr-xt/cmd/while.t15
2 files changed, 23 insertions, 4 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index af8b947794..af31a1c134 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 392c13779f..515a7b6f9e 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";
+ }
+}