From: Robin Houston Date: Wed, 14 Mar 2001 02:45:51 +0000 (+0000) Subject: PATCH for [ID 20010305.003] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b2447bced8c335535d7a233343e70749bff7b24;p=p5sagit%2Fp5-mst-13.2.git PATCH for [ID 20010305.003] Message-ID: <20010314024551.A16207@puffinry.freeserve.co.uk> p4raw-id: //depot/perl@9141 --- diff --git a/pp_ctl.c b/pp_ctl.c index 46e7ef0..99e3ff4 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -2454,6 +2454,7 @@ PP(pp_goto) if (label && *label) { OP *gotoprobe = 0; + bool leaving_eval = FALSE; /* find label */ @@ -2463,6 +2464,7 @@ PP(pp_goto) cx = &cxstack[ix]; switch (CxTYPE(cx)) { case CXt_EVAL: + leaving_eval = TRUE; if (CxREALEVAL(cx)) { gotoprobe = PL_eval_root; /* XXX not good for nested eval */ break; @@ -2505,6 +2507,17 @@ PP(pp_goto) if (!retop) DIE(aTHX_ "Can't find label %s", label); + /* if we're leaving an eval, check before we pop any frames + that we're not going to punt, otherwise the error + won't be caught */ + + if (leaving_eval && *enterops && enterops[1]) { + I32 i; + for (i = 1; enterops[i]; i++) + if (enterops[i]->op_type == OP_ENTERITER) + DIE(aTHX_ "Can't \"goto\" into the middle of a foreach loop"); + } + /* pop unwanted frames */ if (ix < cxstack_ix) { diff --git a/t/op/eval.t b/t/op/eval.t index 11fbfd0..f4d4be5 100755 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -1,6 +1,6 @@ #!./perl -print "1..40\n"; +print "1..41\n"; eval 'print "ok 1\n";'; @@ -206,3 +206,18 @@ print $@; print "ok $x\n"; $x++; } + +# Check that eval catches bad goto calls +# (BUG ID 20010305.003) +{ + eval { + eval { goto foo; }; + print ($@ ? "ok 41\n" : "not ok 41\n"); + last; + foreach my $i (1) { + foo: print "not ok 41\n"; + print "# jumped into foreach\n"; + } + }; + print "not ok 41\n" if $@; +}