Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

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

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


perlbug-comment at perl

Jun 24, 2012, 10:44 PM

Post #1 of 6 (108 views)
Permalink
[perl #113554] my() with empty list causes weird error

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


perlbug-followup at perl

Jun 25, 2012, 7:29 AM

Post #2 of 6 (103 views)
Permalink
[perl #113554] my() with empty list causes weird error [In reply to]

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, and it
should be an error. If the compiler detects an invalid declaration it
should help the author and not silently allow to do nothing.

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;"



$ perlall -m do -e '"my ();"'
/usr/local/bin/perl5.16.0-nt -e "my ();"
Can't declare stub in "my" at -e line 1, near ");"
Execution of -e aborted due to compilation errors.
/usr/local/bin/perl5.14.2-nt -e "my ();"
Can't declare stub in "my" at -e line 1, near ");"
Execution of -e aborted due to compilation errors.
/usr/local/bin/perl5.12.4 -e "my ();"
sh: 1: /usr/local/bin/perl5.12.4: not found
/usr/local/bin/perl5.10.1-nt -e "my ();"
Can't declare stub in "my" at -e line 1, near ");"
Execution of -e aborted due to compilation errors.
/usr/local/bin/perl5.8.9d -e "my ();"
Can't declare stub in "my" at -e line 1, near ");"
Execution of -e aborted due to compilation errors.
/usr/local/bin/perl5.8.8d-nt -e "my ();"
Can't declare stub in "my" at -e line 1, near ");"
Execution of -e aborted due to compilation errors.
/usr/local/bin/perl5.8.5d-nt -e "my ();"
Can't declare stub in "my" at -e line 1, near ");"
Execution of -e aborted due to compilation errors.
/usr/local/bin/perl5.8.4d-nt -e "my ();"
Can't declare stub in "my" at -e line 1, near ");"
Execution of -e aborted due to compilation errors.
/usr/local/bin/perl5.6.2-nt -e "my ();"
Can't declare stub in "my" at -e line 1, near ");"
Execution of -e aborted due to compilation errors.

Please revert 8b8c1fb. This broke it, and did not fix it.
For consistency with older perls I would also not change the error
message, but maybe explain it in a pod, if we would have a
pod with all parser/compiler-time error messages collected.
A "stub" is an empty expression placeholder to me.
--
Reini Urban

---
via perlbug: queue: perl5 status: resolved
https://rt.perl.org:443/rt3/Ticket/Display.html?id=113554


perlbug-followup at perl

Jun 25, 2012, 8:33 AM

Post #3 of 6 (105 views)
Permalink
[perl #113554] my() with empty list causes weird error [In reply to]

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.

> and it
> should be an error.

Why? If my can take a list, why not an empty one?

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

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

--

Father Chrysostomos


---
via perlbug: queue: perl5 status: resolved
https://rt.perl.org:443/rt3/Ticket/Display.html?id=113554


perlbug-followup at perl

Jun 25, 2012, 1:51 PM

Post #4 of 6 (106 views)
Permalink
[perl #113554] my() with empty list causes weird error [In reply to]

On Mon Jun 25 13:38:28 2012, rurban wrote:
> On Mon, Jun 25, 2012 at 10:33 AM, Father Chrysostomos via RT
> <perlbug-followup [at] perl> 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.

That could break code for anyone who is using 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 ;"

I’m afraid your answer is tautological. Why *shouldn’t* it be allowed
to take an empty list?

Allowing an empty list provides a clear benefit and makes things more
consistent. What problems could it cause?

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

But ()=() is allowed.

>
> >> 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
> #endif
> 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;

No, I think it is to allow our($s), but not our(${"s"}).

--

Father Chrysostomos


---
via perlbug: queue: perl5 status: resolved
https://rt.perl.org:443/rt3/Ticket/Display.html?id=113554


perlbug-comment at perl

Jul 6, 2012, 5:02 AM

Post #5 of 6 (93 views)
Permalink
[perl #113554] my() with empty list causes weird error [In reply to]

On Thu Jul 05 20:36:01 2012, perl.p5p [at] rjbs wrote:
> * Ricardo Signes <perl.p5p [at] rjbs> [2012-06-25T20:38:46]
> > It seems open to change. The question is: what's the cost, and
> what's the
> > benefit?
>
> I think the feature seems low in both cost and benefit, with the key
> difference
> that once we allow "my();" we will be hard pressed to disallow it
> later, if we
> realize we should,

Realize we should make lists inconsistent? See below.

> as we'll be breaking something. I'm not entirely
> opposed to
> breaking code at the edges of sanity, but it sounds like there's very
> little
> practical argument to make this edge case permitted. Allowing "my()"
> won't
> really make it act like "normal" built-ins. It will make it a little
> more like
> one, but not enough to be worth even the relatively small risk of
> future
> headaches.

I hope you are still open to remonstration. perldata says:

The null list is represented by (). Interpolating it in a list
has no effect.

But what it says is not true of my($a,(),$b) even though
my($a,($b,((((($c))))))) works.

So things *are* inconsistent in that case. my() does not allow a list
of variables in the usual Perl sense, but a list consisting of
variables, and possibly sublists of variables, possibly with the + unary
operator, but no nested empty lists.

I still fail to see how that exception is a good thing.

I would consider any case where the implementation of () (an actual op
in its own right, as opposed to nothingness) leaks out to be a bug. ()
is supposed to be nothingness; the fact that it cannot be implemented
that way for technical reasons only leaks out with my()/our()/local().

> As for the "this was made legal in 1999, but failed because of a
> separate
> issue," that may be the case, but I don't believe it was really done
> deliberately.

The grammar already allowed it before that, but it was made more
explicit when the myterm rule had to be separated from term, for
attributes to work.

--

Father Chrysostomos


perlbug-comment at perl

Jul 8, 2012, 12:17 AM

Post #6 of 6 (96 views)
Permalink
[perl #113554] my() with empty list causes weird error [In reply to]

On Sat Jul 07 23:03:09 2012, aristotle wrote:
> the concept of “zero” is not exactly novel.

Ah, but it was at one time. :-)

--

Father Chrysostomos

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.