develooper Front page | perl.perl5.porters | Postings from June 2012

Re: [perl #113554] my() with empty list causes weird error

Thread Previous | Thread Next
Reini Urban
June 25, 2012 13:38
Re: [perl #113554] my() with empty list causes weird error
Message ID:
On Mon, Jun 25, 2012 at 10:33 AM, Father Chrysostomos via RT
<> wrote:
> On Mon Jun 25 07:29:17 2012, rurban wrote:
>> On Sun Jun 24 22:44:27 2012, doy wrote:
>> > Fixed in 8b8c1fb. It looks like this was a bug that was fixed during
>> the
>> > course of MAD development, but was added back into the core with
>> #ifdef
>> > PERL_MAD just because it was different from the existing core code.
>> >
>> > (Also, for future reference: 'stub' is the name of the internal perl
>> > opcode which generates the '()' construct. See �perl -MO=Concise -
>> E'my
>> > @x = ()'� for instance.)
>> I disagree.
>> The error message is not weird, it is consistent with all perls,
> Not mad builds.

Then make MAD consistent with the default non-mad.

>> 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.
lexicals are our default, non lexicals are warned.
Empty declarations are syntax errors, if "my ();" or "my ;"

>> 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.

>> 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.
>> $ perl -e"my;"
>> syntax error at -e line 1, near "my;"
> That is consistent with this:
> $ perl -le 'sort {$a<=>$b} ()'
> $ perl -le 'sort {$a<=>$b}'
> syntax error at -e line 1, at EOF
> Execution of -e aborted due to compilation errors.

That's not an variable declaration, that's the rhs (right hand side)
of an op. An empty list.

I'm open to change the syntax error message.
See e.g. the attached patch which changes "STUB" to "()"

$ ./miniperl -e'our ()'
Can't declare () in "our" at -e line 1, at EOF
Execution of -e aborted due to compilation errors.

The real problem is op.c:2476
#ifdef PERL_MAD
	       || type == OP_STUB
to silence the error message with MAD and the underlying cause within MAD.

BTW: The comment with MJD 20011224 at op.c:2484 is to allow a glob rhs;
  our $a =*g;
Reini Urban

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About