This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #91514] Use correct error msg for default
authorFather Chrysostomos <sprout@cpan.org>
Fri, 16 Dec 2011 17:25:30 +0000 (09:25 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 16 Dec 2011 17:54:17 +0000 (09:54 -0800)
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.

MANIFEST
op.c
op.h
pod/perldiag.pod
pp_ctl.c
t/lib/croak/pp_ctl [new file with mode: 0644]

index 08f12dc..e38b289 100644 (file)
--- 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 7985fea..ea6c89a 100644 (file)
--- 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 d61198f..0758f9c 100644 (file)
--- a/op.h
+++ b/op.h
@@ -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 */
index 6f0a77f..923a811 100644 (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)
index 953a749..a9012ee 100644 (file)
--- 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 (file)
index 0000000..0f075cd
--- /dev/null
@@ -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.