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

[perl #88384] no warning for my $a = 1 if 0;

Thread Next
From:
Father Chrysostomos via RT
Date:
September 24, 2012 00:07
Subject:
[perl #88384] no warning for my $a = 1 if 0;
Message ID:
rt-3.6.HEAD-11172-1348470419-1261.88384-15-0@perl.org
On Thu Jun 28 14:32:27 2012, doy@tozt.net wrote:
> On Thu, Jun 28, 2012 at 01:40:29PM -0500, Jesse Luehrs wrote:
> > On Thu, Jun 28, 2012 at 01:35:14PM -0500, Jesse Luehrs wrote:
> > > > op.h has this:
> > > > 
> > > > /* Private for OP_CONST */
> > > > #define	OPpCONST_NOVER		2	/* no 6; */
> > > > #define	OPpCONST_SHORTCIRCUIT	4	/* eg the constant 5 in (5 ||
foo) */
> > > > #define	OPpCONST_STRICT		8	/* bareword subject to strict 'subs' */
> > > > #define OPpCONST_ENTERED	16	/* Has been entered as symbol. */
> > > > #define OPpCONST_BARE		64	/* Was a bare word (filehandle?). */
> > > > 
> > > > Is OPpCONST_SHORTCIRCUIT true on the constant?
> > > 
> > > It's actually true in both cases - the same part of the code that does
> > > this test also sets that flag unconditionally. This test is
happening in
> > > inside newLOGOP when an OP_AND is compiled, because "$foo if $bar" is
> > > translated into "$bar and $foo" by the parser itself:
> > > 
> > >         |       expr IF expr
> > >                         { $$ = newLOGOP(OP_AND, 0, $3, $1);
> > >                           TOKEN_GETMAD($2,$$,'i');
> > >                         }
> > 
> > It does strike me though that we could just differentiate there
> > directly, by having the parser set an op flag in that case. I don't
> > think OPf_SPECIAL is used for OP_AND yet? Let me try that.
> 
> So I tried this (and updated the branch), but this still isn't quite
> right - now cases like "0 and my $foo" are not warned for, even outside
> of an if block. This really does have to happen elsewhere, I think - we
> need to be able to say "is the entire scope of this declaration going to
> be optimized away by the parent op?", and we can't do that from the
> point where the OP_AND is created. I'm not really sure how to go about
> changing that though/:

I know more about this now than before implementing lexical subs, so I
actually have a suggestion:

The mexpr and texpr rules in perly.y are probably where you want to set
a flag.  Those rules are used only inside keyword(...){}.

-- 

Father Chrysostomos


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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About