[perl #91514] Use correct error msg for default

This commit not only mentions default (as opposed to when)
in the error message about it being outside a topicalizer, but
also normalises those error messages, making them consistent with
continue and other loop controls.  It also makes the perldiag
entry for when actually match the error message.
This commit is contained in:
Father Chrysostomos 2011-12-16 09:25:30 -08:00
parent f4912a505d
commit fc7debfb01
6 changed files with 33 additions and 9 deletions

View File

@ -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

1
op.c
View File

@ -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;
}

3
op.h
View File

@ -131,7 +131,8 @@ Deprecated. Use C<GIMME_V> 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 */

View File

@ -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<default> block that is neither inside a
C<foreach> loop nor a C<given> block. (Note that this error is
issued on exit from the C<default> block, so you won't get the
error if you use an explicit C<continue>.)
=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<foreach>
loop nor a C<given> block. (Note that this error is issued on exit
from the C<when> block, so you won't get the error if the match fails,
or if you use an explicit C<continue>.)
=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<foreach>
loop nor a C<given> block. (Note that this error is issued on exit
from the C<when> block, so you won't get the error if the match fails,
or if you use an explicit C<continue>.)
=item Can't x= to read-only value
(F) You tried to repeat a constant value (often the undefined value)

View File

@ -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);

12
t/lib/croak/pp_ctl Normal file
View File

@ -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.