From: Father Chrysostomos Date: Sat, 14 Dec 2013 01:48:34 +0000 (-0800) Subject: Fix ‘Can't declare null operation in "my"’ X-Git-Tag: upstream/5.20.0~1012 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4748e0020f8a6874cca537d6f4191150c046410c;p=platform%2Fupstream%2Fperl.git Fix ‘Can't declare null operation in "my"’ This message is very unhelpful. This was brought up in ticket #115688. --- diff --git a/op.c b/op.c index 627486d..a9dafaa 100644 --- 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")); diff --git a/t/lib/croak/op b/t/lib/croak/op index 4cc82af..603f718 100644 --- a/t/lib/croak/op +++ b/t/lib/croak/op @@ -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