This message is very unhelpful. This was brought up in
ticket #115688.
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"));
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