Skip to content

Commit b537774

Browse files
author
Father Chrysostomos
committed
pp_ctl.c: Move goto-into-foreach error
Put it in a static function, instead of repeating the code. This way I can add more conditions to that code in subsequent commits.
1 parent 436908e commit b537774

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pp_ctl.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,17 @@ S_dofindlabel(pTHX_ OP *o, const char *label, STRLEN len, U32 flags, OP **opstac
27092709
}
27102710

27112711

2712+
static void
2713+
S_check_op_type(pTHX_ OP * const o)
2714+
{
2715+
/* Eventually we may want to stack the needed arguments
2716+
* for each op. For now, we punt on the hard ones. */
2717+
/* XXX This comment seems to me like wishful thinking. --sprout */
2718+
if (o->op_type == OP_ENTERITER)
2719+
Perl_croak(aTHX_
2720+
"Can't \"goto\" into the middle of a foreach loop");
2721+
}
2722+
27122723
/* also used for: pp_dump() */
27132724

27142725
PP(pp_goto)
@@ -3050,8 +3061,7 @@ PP(pp_goto)
30503061
if (leaving_eval && *enterops && enterops[1]) {
30513062
I32 i;
30523063
for (i = 1; enterops[i]; i++)
3053-
if (enterops[i]->op_type == OP_ENTERITER)
3054-
DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
3064+
S_check_op_type(aTHX_ enterops[i]);
30553065
}
30563066

30573067
if (*enterops && enterops[1]) {
@@ -3077,10 +3087,7 @@ PP(pp_goto)
30773087
ix = enterops[1]->op_type == OP_ENTER && in_block ? 2 : 1;
30783088
for (; enterops[ix]; ix++) {
30793089
PL_op = enterops[ix];
3080-
/* Eventually we may want to stack the needed arguments
3081-
* for each op. For now, we punt on the hard ones. */
3082-
if (PL_op->op_type == OP_ENTERITER)
3083-
DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop");
3090+
S_check_op_type(aTHX_ PL_op);
30843091
PL_op->op_ppaddr(aTHX);
30853092
}
30863093
PL_op = oldop;

0 commit comments

Comments
 (0)