eval 'goto &foo' is already banned, and the try-version usually
coredumps due to the code assuming the CxEVAL is actually a CxSUB.
Anyway exiting an eval but preserving "it's" @_ doesn't make much
sense.
p4raw-id: //depot/perl@24532
you tried to jump out of a sort() block or subroutine, which is a no-no.
See L<perlfunc/goto>.
-=item Can't goto subroutine from an eval-string
+=item Can't goto subroutine from an eval-%s
(F) The "goto subroutine" call can't be used to jump out of an eval
-"string". (You can use it to jump out of an eval {BLOCK}, but you
-probably don't want to.)
+"string" or block.
=item Can't goto subroutine outside a subroutine
if (cxix < cxstack_ix)
dounwind(cxix);
TOPBLOCK(cx);
- if (CxREALEVAL(cx))
- DIE(aTHX_ "Can't goto subroutine from an eval-string");
+ if (CxTYPE(cx) == CXt_EVAL)
+ if (CxREALEVAL(cx))
+ DIE(aTHX_ "Can't goto subroutine from an eval-string");
+ else
+ DIE(aTHX_ "Can't goto subroutine from an eval-block");
if (CxTYPE(cx) == CXt_SUB && cx->blk_sub.hasargs) {
/* put @_ back onto stack */
AV* av = cx->blk_sub.argarray;
use warnings;
use strict;
-plan tests => 54;
+plan tests => 56;
our $foo;
while ($?) {
is($r, "ok", 'redo and goto');
}
+# goto &foo not allowed in evals
+
+sub null { 1 };
+eval 'goto &null';
+like($@, qr/Can't goto subroutine from an eval-string/, 'eval string');
+eval { goto &null };
+like($@, qr/Can't goto subroutine from an eval-block/, 'eval block');