develooper Front page | perl.perl5.porters | Postings from August 2013

[perl #118753] String constant used in elsif causes bogus warning

Thread Next
From:
Father Chrysostomos via RT
Date:
August 20, 2013 16:05
Subject:
[perl #118753] String constant used in elsif causes bogus warning
Message ID:
rt-3.6.HEAD-1873-1377014714-740.118753-15-0@perl.org
On Thu Jul 04 07:59:28 2013, demerphq wrote:
> Found in perl 5.14.2 and in bleadperl, note the warning about constant
> in void context:
> 
> $ ./perl -Ilib -lwe'BEGIN{eval "sub C() { q() }";} if ($x) { print 1 }
> elsif (C) { print 2 }'
> Useless use of a constant ("") in void context at -e line 1.
> Name "main::x" used only once: possible typo at -e line 1.
> 
> Changing the constant to a 0 avoids the warning:
> 
> $ ./perl -Ilib -lwe'BEGIN{eval "sub C() { 0 }";} if ($x) { print 1 }
> elsif (C) { print 2 }'
> Name "main::x" used only once: possible typo at -e line 1.
> 
> Rafael points out that you dont need the constant for it:
> 
> $ ./perl -Ilib -lwe'if ($x) { print 1 } elsif ("") { print 2 }'
> Useless use of a constant ("") in void context at -e line 1.
> Name "main::x" used only once: possible typo at -e line 1.
> 
> And he explains that this is due to an optimization. Apparently we
> should special case *any* false constant, not just 1 and 0.

The newSTATEOP in the ELSIF block in perly.y stops newLOGOP from seeing
the constant on the lhs (just from reading code; unconfirmed).

I suspect this is actually a regression, caused by:

commit f6f3a1fea2bda9d33f9cc5367b630a21738c9def
Author: Rafael Garcia-Suarez <rgarciasuarez@gmail.com>
Date:   Fri Apr 18 10:42:17 2008 +0000

    Fix the line-number-in-elsif longstanding bug.
    This patch does two things :
    - newSTATEOP now nullifies the state op it
      just created if OPf_SPECIAL is passed to it
      in flags
    - the parser now inserts a nullified stateop
      in the expression block of an elsif
    
    p4raw-id: //depot/perl@33710

I’m running a bisect now.

-- 

Father Chrysostomos


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

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