Skip to content

Commit 71f977b

Browse files
committed
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.
1 parent ce96f1e commit 71f977b

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

pp_ctl.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,6 +3551,8 @@ PP(pp_goto)
35513551

35523552
PERL_ASYNC_CHECK();
35533553

3554+
bool into_construct = FALSE;
3555+
35543556
if (label_len) {
35553557
OP *gotoprobe = NULL;
35563558
bool leaving_eval = FALSE;
@@ -3652,9 +3654,7 @@ PP(pp_goto)
36523654
? 2
36533655
: 1;
36543656
if (enterops[i])
3655-
deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT,
3656-
"5.42",
3657-
"Use of \"goto\" to jump into a construct");
3657+
into_construct = TRUE;
36583658
}
36593659

36603660
/* pop unwanted frames */
@@ -3686,6 +3686,12 @@ PP(pp_goto)
36863686
}
36873687
}
36883688

3689+
if (into_construct)
3690+
deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT,
3691+
"5.42",
3692+
"Use of \"goto\" to jump into a construct");
3693+
3694+
36893695
if (do_dump) {
36903696
#ifdef VMS
36913697
if (!retop) retop = PL_main_start;

t/lib/croak/pp_ctl

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,40 @@
11
__END__
22
# NAME goto into foreach
3-
no warnings 'deprecated';
43
goto f;
54
foreach(1){f:}
65
EXPECT
7-
Can't "goto" into the middle of a foreach loop at - line 3.
6+
Can't "goto" into the middle of a foreach loop at - line 2.
87
########
98
# NAME goto into given
10-
no warnings 'deprecated';
119
goto f;
1210
CORE::given(1){f:}
1311
EXPECT
14-
Can't "goto" into a "given" block at - line 3.
12+
Can't "goto" into a "given" block at - line 2.
1513
########
1614
# NAME goto from given topic expression
17-
no warnings 'deprecated';
1815
CORE::given(goto f){f:}
1916
EXPECT
20-
Can't "goto" into a "given" block at - line 2.
17+
Can't "goto" into a "given" block at - line 1.
2118
########
2219
# NAME goto into expression
23-
no warnings 'deprecated';
2420
eval { goto a; 1 + do { a: } }; warn $@;
2521
eval { goto b; meth { b: } }; warn $@;
2622
eval { goto c; map { c: } () }; warn $@;
2723
eval { goto d; f(do { d: }) }; die $@;
2824
EXPECT
25+
Can't "goto" into a binary or list expression at - line 1.
2926
Can't "goto" into a binary or list expression at - line 2.
3027
Can't "goto" into a binary or list expression at - line 3.
3128
Can't "goto" into a binary or list expression at - line 4.
32-
Can't "goto" into a binary or list expression at - line 5.
3329
########
3430
# NAME dump with computed label
35-
no warnings 'deprecated';
3631
my $label = "foo";
3732
CORE::dump $label;
3833
EXPECT
39-
Can't find label foo at - line 3.
34+
Can't find label foo at - line 2.
4035
########
4136
# NAME when outside given
42-
use 5.01; no warnings 'deprecated';
37+
use 5.01;
4338
when(undef){}
4439
EXPECT
4540
Can't "when" outside a topicalizer at - line 2.

0 commit comments

Comments
 (0)