Fix ‘Can't declare null operation in "my"’
authorFather Chrysostomos <sprout@cpan.org>
Sat, 14 Dec 2013 01:48:34 +0000 (17:48 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 14 Dec 2013 02:06:59 +0000 (18:06 -0800)
This message is very unhelpful.  This was brought up in
ticket #115688.

op.c
t/lib/croak/op

diff --git a/op.c b/op.c
index 627486d..a9dafaa 100644 (file)
--- a/op.c
+++ b/op.c
@@ -2799,8 +2799,14 @@ S_move_proto_attr(pTHX_ OP **proto, OP **attrs, const GV * name)
 static void
 S_cant_declare(pTHX_ OP *o)
 {
+    if (o->op_type == OP_NULL
+     && (o->op_flags & (OPf_SPECIAL|OPf_KIDS)) == OPf_KIDS)
+        o = cUNOPo->op_first;
     yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"",
-                             OP_DESC(o),
+                             o->op_type == OP_NULL
+                               && o->op_flags & OPf_SPECIAL
+                                 ? "do block"
+                                 : OP_DESC(o),
                              PL_parser->in_my == KEY_our   ? "our"   :
                              PL_parser->in_my == KEY_state ? "state" :
                                                              "my"));
index 4cc82af..603f718 100644 (file)
@@ -50,6 +50,18 @@ my main $f;
 EXPECT
 No such class field "c" in variable $f of type main at - line 3.
 ########
+# NAME Can't declare conditional
+my($a?$b:$c)
+EXPECT
+Can't declare conditional expression in "my" at - line 1, at EOF
+Execution of - aborted due to compilation errors.
+########
+# NAME Can't declare do block
+my(do{})
+EXPECT
+Can't declare do block in "my" at - line 1, at EOF
+Execution of - aborted due to compilation errors.
+########
 # NAME delete BAD
 delete $x;
 EXPECT