On Mon, Jun 25, 2012 at 5:15 PM, Lukas Mai <l.mai@web.de> wrote: > On 2012-06-25 Reini Urban via RT wrote: >> On Mon, Jun 25, 2012 at 10:33 AM, Father Chrysostomos via RT >> <perlbug-followup@perl.org> wrote: >> > On Mon Jun 25 07:29:17 2012, rurban wrote: > >> >> and it should be an error. >> > >> > Why? If my can take a list, why not an empty one? >> >> my is perl's declaration syntax. It expects one or many lexical >> variable names, not zero. > > No, it expects exactly one variable name, or a list of variables > enclosed in parens. And lists can be empty. Sorry, but it was an syntax error until 5.17.2 until how made it suddenly valid syntax. It was also valid syntax for MAD. >> lexicals are our default, non lexicals are warned. >> Empty declarations are syntax errors, if "my ();" or "my ;" > > Yes, and we should fix the first one. I disagree that it's purely a > syntax error because the grammar clearly allows it and it has an > obvious interpretation. Sorry, the grammar clearly disallowed it until someone patched it to silently ignore this syntax error. Allowing syntax errors for dead and wrong code is not helpful. It is rather the opposite. >> >> If the compiler detects an invalid declaration it >> >> should help the author and not silently allow to do nothing. >> > >> > What is invalid about an empty list? >> >> It is an empty declaration, which is an syntax error. >> empty lists rhs are perfectly valid, even in declarations >> such as: >> my ($a,$b) = (); >> but not in a lhs declaration. > > () = 42; works fine. It also has an obvious interpretation: if the LHS > is shorter than the RHS, the remaining items are ignored. In this case > the LHS has zero elements and all values in the RHS list are ignored. This is old code before lexicals were introduced and it should be optimized away. You can perlbug that if you like. pp_aassign is heavy enough and should not be bothered with such useless cycles. $ perl -MO=Concise -e'()=42;' 7 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 6 <2> aassign[t1] vKS ->7 - <1> ex-list lK ->5 3 <0> pushmark s ->4 4 <$> const(IV 42) s ->5 - <1> ex-list lK ->6 5 <0> pushmark s ->6 - <0> stub lPRM* ->- Unfortunately our parser is a bit degenerated to be able to detect such nonsense. > "lhs declaration" isn't a meaningful concept: > Syntactically speaking you can add add "my" in front of a variable in > any valid expression. It doesn't matter whether it's the LHS of > anything. lhs of my declarations is a meaningful concept sorry. see perly for myterm. That's why my () was invalid until someone allowed that nonsense. Do you really want Perl to compile invalid syntax starting with 5.17 just because your code generator sucks? You didn't even write your code to use sassign for variable declarations of single argument assignment which is utter non-sense. And now Perl's aassign must bear your nonsense? >> >> Re the consistency argument: Why allow now empty declarations? This >> >> makes it inconsistent. >> >> >> >> Why should "my ();" parse correctly? >> >> Why should "my;" parse correctly? Both are clearly syntax errors. > > "my ()" should parse correctly because you'd have to introduce a > special case to disallow it. (I'm talking about Perl here, not perl. I > don't care much about how it's implemented.) I did not disallow it, I changed the error message. It was someone else who brought the parser up to MAD inconsistency instead of changing the error message and fixing MAD. my (); always threw an syntax error. It was the error message you did not understand. Which I fixed for you. -- Reini Urban http://cpanel.net/ http://www.perl-compiler.org/Thread Previous | Thread Next