Skip to content
Open
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
35 changes: 34 additions & 1 deletion t/op/goto-sub.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BEGIN {
use v5.16;
use warnings;
use Config;
plan tests => 41;
plan tests => 44;

# Excerpts from 'perldoc -f goto' as of perl-5.40.1 (Aug 2025)
#
Expand Down Expand Up @@ -373,6 +373,39 @@ SKIP:
is $fac->(5), 120, 'recursion via goto __SUB__';
}

# GH 23811 goto &NAME where block evaluates to coderef
{
local $@;
my $hw = 'hello world';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is $hw for?


eval {
my $coderef = sub { return $hw; };
my $rv = goto &{ 1; $coderef; };
};
like($@, qr/^Can't goto subroutine from an eval-block/,
"Can't goto subroutine (block which evaluates to coderef) from an eval block");

undef $@;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undef $@ is redundant before eval. Every eval resets $@.


eval {
sub helloworld { return $hw; }
my $rv = goto &helloworld;
};
like($@, qr/^Can't goto subroutine from an eval-block/,
"Can't goto named subroutine from an eval block");

undef $@;

eval {
my $coderef = sub { return $hw; };
my $rv = goto &$coderef;
};
like($@, qr/^Can't goto subroutine from an eval-block/,
"Can't goto subroutine (&coderef) from an eval block");
}



# Final test: ensure that we saw no deprecation warnings
# ... but rework this to count fatalizations once work is more developed

Expand Down
Loading