Skip to content

Commit e7240d2

Browse files
committed
test 'goto __SUB__' tail recursion
Fixes #23804.
1 parent b7b77ff commit e7240d2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

t/op/goto-sub.t

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ BEGIN {
77
require './charset_tools.pl';
88
}
99

10+
use v5.16;
1011
use warnings;
11-
use strict;
1212
use Config;
13-
plan tests => 40;
13+
plan tests => 41;
1414

1515
# Excerpts from 'perldoc -f goto' as of perl-5.40.1 (Aug 2025)
1616
#
@@ -358,6 +358,21 @@ SKIP:
358358
}
359359

360360

361+
# GH 23804 goto __SUB__
362+
{
363+
my $fac = sub {
364+
unshift @_, 1;
365+
goto sub {
366+
my ($acc, $i) = @_;
367+
return $acc if $i < 2;
368+
@_ = ($acc * $i, $i - 1);
369+
goto __SUB__;
370+
};
371+
};
372+
373+
is $fac->(5), 120, 'recursion via goto __SUB__';
374+
}
375+
361376
# Final test: ensure that we saw no deprecation warnings
362377
# ... but rework this to count fatalizations once work is more developed
363378

0 commit comments

Comments
 (0)