Skip to content

Commit bdd2c79

Browse files
committed
Add test and docs about multiple identical block labels
Fixes #18369.
1 parent 20984aa commit bdd2c79

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pod/perlsyn.pod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ If the LABEL is omitted, the loop control statement
330330
refers to the innermost enclosing loop. This may include dynamically
331331
searching through your call-stack at run time to find the LABEL. Such
332332
desperate behavior triggers a warning if you use the C<use warnings>
333-
pragma or the B<-w> flag.
333+
pragma or the B<-w> flag. If more than one label with the same name
334+
occurs, any reference to that name refers to the one labelling the
335+
innermost enclosing loop.
334336

335337
If the condition expression of a C<while> statement is based
336338
on any of a group of iterative expression types then it gets

t/op/loopctl.t

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BEGIN {
3636
set_up_inc(qw(. ../lib));
3737
}
3838

39-
plan( tests => 67 );
39+
plan( tests => 69 );
4040

4141
my $ok;
4242

@@ -922,6 +922,23 @@ TEST41: {
922922
}
923923
cmp_ok($ok,'==',1,'dynamically scoped');
924924

925+
TEST42: { # GH #18369
926+
my $outer = 0;
927+
my $inner = 0;
928+
L:
929+
for my $i (0 .. 0) {
930+
$outer++;
931+
932+
L:
933+
for my $j (0 .. 0) {
934+
$inner++;
935+
redo L if $inner < 10;
936+
}
937+
}
938+
939+
is ($inner, 10, "redo label refers to innermost enclosing one");
940+
is ($outer, 1, "redo label doesn't refer to outermost enclosing one");
941+
}
925942

926943
# [perl #27206] Memory leak in continue loop
927944
# Ensure that the temporary object is freed each time round the loop,

0 commit comments

Comments
 (0)