Skip to content

Commit 8493142

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 8493142

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pp_ctl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,7 @@ PP(pp_goto)
32503250
I32 ix;
32513251
PERL_CONTEXT *cx;
32523252
OP *enterops[GOTO_DEPTH];
3253+
bool into_construct = FALSE;
32533254
const char *label = NULL;
32543255
STRLEN label_len = 0;
32553256
U32 label_flags = 0;
@@ -3652,9 +3653,7 @@ PP(pp_goto)
36523653
? 2
36533654
: 1;
36543655
if (enterops[i])
3655-
deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT,
3656-
"5.42",
3657-
"Use of \"goto\" to jump into a construct");
3656+
into_construct = TRUE;
36583657
}
36593658

36603659
/* pop unwanted frames */
@@ -3686,6 +3685,12 @@ PP(pp_goto)
36863685
}
36873686
}
36883687

3688+
if (into_construct)
3689+
deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT,
3690+
"5.42",
3691+
"Use of \"goto\" to jump into a construct");
3692+
3693+
36893694
if (do_dump) {
36903695
#ifdef VMS
36913696
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)