Skip to content

Commit d0a88a3

Browse files
committed
Demonstrate exceptions for goto &NAME
Provide simple examples of goto &NAME syntax used incorrectly. Addresses: GH #23811 Remove two superfluous statements, per review by @mauke.
1 parent 6c69639 commit d0a88a3

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

t/op/goto-sub.t

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BEGIN {
1010
use v5.16;
1111
use warnings;
1212
use Config;
13-
plan tests => 41;
13+
plan tests => 44;
1414

1515
# Excerpts from 'perldoc -f goto' as of perl-5.40.1 (Aug 2025)
1616
#
@@ -373,6 +373,35 @@ SKIP:
373373
is $fac->(5), 120, 'recursion via goto __SUB__';
374374
}
375375

376+
# GH 23811 goto &NAME where block evaluates to coderef
377+
{
378+
local $@;
379+
my $hw = 'hello world';
380+
381+
eval {
382+
my $coderef = sub { return $hw; };
383+
my $rv = goto &{ 1; $coderef; };
384+
};
385+
like($@, qr/^Can't goto subroutine from an eval-block/,
386+
"Can't goto subroutine (block which evaluates to coderef) from an eval block");
387+
388+
eval {
389+
sub helloworld { return $hw; }
390+
my $rv = goto &helloworld;
391+
};
392+
like($@, qr/^Can't goto subroutine from an eval-block/,
393+
"Can't goto named subroutine from an eval block");
394+
395+
eval {
396+
my $coderef = sub { return $hw; };
397+
my $rv = goto &$coderef;
398+
};
399+
like($@, qr/^Can't goto subroutine from an eval-block/,
400+
"Can't goto subroutine (&coderef) from an eval block");
401+
}
402+
403+
404+
376405
# Final test: ensure that we saw no deprecation warnings
377406
# ... but rework this to count fatalizations once work is more developed
378407

0 commit comments

Comments
 (0)