Don't warn about jumping into a construct if we're DIE-ing

There are many cases where we throw exceptions if you attempt to goto
somewhere you have no business going. We'd *also* throw a deprecation
warning in these cases, which just seems silly. Deprecated means "this
will stop working eventually", so there's no need to throw that when
we're just going to die right now.
This commit is contained in:
Matthew Horsfall 2025-11-14 18:12:07 -05:00 committed by James E Keenan
parent 9bb0c18be2
commit f7c24445e8
2 changed files with 11 additions and 9 deletions

View File

@ -3250,6 +3250,7 @@ PP(pp_goto)
I32 ix;
PERL_CONTEXT *cx;
OP *enterops[GOTO_DEPTH];
bool into_construct = FALSE;
const char *label = NULL;
STRLEN label_len = 0;
U32 label_flags = 0;
@ -3652,9 +3653,7 @@ PP(pp_goto)
? 2
: 1;
if (enterops[i])
deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT,
"5.42",
"Use of \"goto\" to jump into a construct");
into_construct = TRUE;
}
/* pop unwanted frames */
@ -3686,6 +3685,12 @@ PP(pp_goto)
}
}
if (into_construct)
deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT,
"5.42",
"Use of \"goto\" to jump into a construct");
if (do_dump) {
#ifdef VMS
if (!retop) retop = PL_main_start;

View File

@ -1,23 +1,20 @@
__END__
# NAME goto into foreach
no warnings 'deprecated';
goto f;
foreach(1){f:}
EXPECT
Can't "goto" into the middle of a foreach loop at - line 3.
Can't "goto" into the middle of a foreach loop at - line 2.
########
# NAME goto into given
no warnings 'deprecated';
goto f;
CORE::given(1){f:}
EXPECT
Can't "goto" into a "given" block at - line 3.
Can't "goto" into a "given" block at - line 2.
########
# NAME goto from given topic expression
no warnings 'deprecated';
CORE::given(goto f){f:}
EXPECT
Can't "goto" into a "given" block at - line 2.
Can't "goto" into a "given" block at - line 1.
########
# NAME goto into expression
eval { goto a; 1 + do { a: } }; warn $@;