From d0a88a3984ce761f3f4d7b0e5a1fabe32d0a5150 Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Mon, 6 Oct 2025 08:28:59 -0400 Subject: [PATCH] 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. --- t/op/goto-sub.t | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/t/op/goto-sub.t b/t/op/goto-sub.t index 83b86493586f..c154263e8c2c 100644 --- a/t/op/goto-sub.t +++ b/t/op/goto-sub.t @@ -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) # @@ -373,6 +373,35 @@ SKIP: is $fac->(5), 120, 'recursion via goto __SUB__'; } +# GH 23811 goto &NAME where block evaluates to coderef +{ + local $@; + my $hw = 'hello world'; + + 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"); + + 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"); + + 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