Skip to content

Add test and docs about multiple identical block labels #23259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pod/perlsyn.pod
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ If the LABEL is omitted, the loop control statement
refers to the innermost enclosing loop. This may include dynamically
searching through your call-stack at run time to find the LABEL. Such
desperate behavior triggers a warning if you use the C<use warnings>
pragma or the B<-w> flag.
pragma or the B<-w> flag. If more than one label with the same name
occurs, any reference to that name refers to the one labelling the
innermost enclosing loop.

If the condition expression of a C<while> statement is based
on any of a group of iterative expression types then it gets
Expand Down
19 changes: 18 additions & 1 deletion t/op/loopctl.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BEGIN {
set_up_inc(qw(. ../lib));
}

plan( tests => 67 );
plan( tests => 69 );

my $ok;

Expand Down Expand Up @@ -922,6 +922,23 @@ TEST41: {
}
cmp_ok($ok,'==',1,'dynamically scoped');

TEST42: { # GH #18369
my $outer = 0;
my $inner = 0;
L:
for my $i (0 .. 0) {
$outer++;

L:
for my $j (0 .. 0) {
$inner++;
redo L if $inner < 10;
}
}

is ($inner, 10, "redo label refers to innermost enclosing one");
is ($outer, 1, "redo label doesn't refer to outermost enclosing one");
}

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