diff --git a/MANIFEST b/MANIFEST index 08f12dc8de..e38b28990a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4982,6 +4982,7 @@ t/lib/commonsense.t See if configuration meets basic needs t/lib/compmod.pl Helper for 1_compile.t t/lib/croak/mg Test croak calls from mg.c t/lib/croak/op Test croak calls from op.c +t/lib/croak/pp_ctl Test croak calls from pp_ctl.c t/lib/croak.t Test calls to Perl_croak() in the C source. t/lib/cygwin.t Builtin cygwin function tests t/lib/dbmt_common.pl Common functionality for ?DBM_File tests diff --git a/op.c b/op.c index 7985fea563..ea6c89ae72 100644 --- a/op.c +++ b/op.c @@ -6150,6 +6150,7 @@ S_newGIVWHENOP(pTHX_ OP *cond, OP *block, /* This is a default {} block */ enterop->op_first = block; enterop->op_flags |= OPf_SPECIAL; + o ->op_flags |= OPf_SPECIAL; o->op_next = (OP *) enterop; } diff --git a/op.h b/op.h index d61198f28c..0758f9c910 100644 --- a/op.h +++ b/op.h @@ -131,7 +131,8 @@ Deprecated. Use C instead. /* On OP_DBSTATE, indicates breakpoint * (runtime property) */ /* On OP_REQUIRE, was seen as CORE::require */ - /* On OP_ENTERWHEN, there's no condition */ + /* On OP_(ENTER|LEAVE)WHEN, there's + no condition */ /* On OP_SMARTMATCH, an implicit smartmatch */ /* On OP_ANONHASH and OP_ANONLIST, create a reference to the new anon hash or array */ diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 6f0a77f99e..923a81172b 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -682,6 +682,13 @@ quotas or other plumbing problems. (F) Only scalar, array, and hash variables may be declared as "my", "our" or "state" variables. They must have ordinary identifiers as names. +=item Can't "default" outside a topicalizer + +(F) You have used a C block that is neither inside a +C loop nor a C block. (Note that this error is +issued on exit from the C block, so you won't get the +error if you use an explicit C.) + =item Can't do inplace edit: %s is not a regular file (S inplace) You tried to use the B<-i> switch on a special file, such as @@ -1225,18 +1232,18 @@ expression pattern. Trying to do this in ordinary Perl code produces a value that prints out looking like SCALAR(0xdecaf). Use the $1 form instead. -=item Can't use "when" outside a topicalizer - -(F) You have used a when() block that is neither inside a C -loop nor a C block. (Note that this error is issued on exit -from the C block, so you won't get the error if the match fails, -or if you use an explicit C.) - =item Can't weaken a nonreference (F) You attempted to weaken something that was not a reference. Only references can be weakened. +=item Can't "when" outside a topicalizer + +(F) You have used a when() block that is neither inside a C +loop nor a C block. (Note that this error is issued on exit +from the C block, so you won't get the error if the match fails, +or if you use an explicit C.) + =item Can't x= to read-only value (F) You tried to repeat a constant value (often the undefined value) diff --git a/pp_ctl.c b/pp_ctl.c index 953a749948..a9012ee57f 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -5024,7 +5024,9 @@ PP(pp_leavewhen) cxix = dopoptogiven(cxstack_ix); if (cxix < 0) - DIE(aTHX_ "Can't use when() outside a topicalizer"); + /* diag_listed_as: Can't "when" outside a topicalizer */ + DIE(aTHX_ "Can't \"%s\" outside a topicalizer", + PL_op->op_flags & OPf_SPECIAL ? "default" : "when"); POPBLOCK(cx,newpm); assert(CxTYPE(cx) == CXt_WHEN); diff --git a/t/lib/croak/pp_ctl b/t/lib/croak/pp_ctl new file mode 100644 index 0000000000..0f075cd783 --- /dev/null +++ b/t/lib/croak/pp_ctl @@ -0,0 +1,12 @@ +__END__ +# NAME when outside given +use 5.01; +when(undef){} +EXPECT +Can't "when" outside a topicalizer at - line 2. +######## +# NAME default outside given +use 5.01; +default{} +EXPECT +Can't "default" outside a topicalizer at - line 2.