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

[perl #121841] Behavior difference in warning for overriding constant v.s. non-constant subroutines

From:
Father Chrysostomos via RT
Date:
September 7, 2014 00:26
Subject:
[perl #121841] Behavior difference in warning for overriding constant v.s. non-constant subroutines
Message ID:
rt-4.0.18-11289-1410049606-10.121841-15-0@perl.org
On Sat May 10 02:24:53 2014, avar wrote:
> 1. $ ./perl -e 'sub x () {1} sub x () {1}'
> 2. $ ./perl -e 'sub x () {1} sub x () {2}'
> 2. Constant subroutine x redefined at -e line 1.
> 3. $ ./perl -we 'sub x () {1} sub x () {1}'
> 3. Constant subroutine x redefined at -e line 1.
> 4. $ ./perl -we 'sub x () {1} sub x () {2}'
> 4. Constant subroutine x redefined at -e line 1.
> 5. $ ./perl -e 'sub y {1} sub y {1}'
> 5. $ ./perl -e 'sub y {1} sub y {2}'
> 6. $ ./perl -we 'sub y {1} sub y {1}'
> 6. Subroutine y redefined at -e line 1.
> 7. $ ./perl -we 'sub y {1} sub y {2}'
> 7. Subroutine y redefined at -e line 1.
> 
> I think it makes sense that if we're going to warn about #2 we should
> also warn about #1 just like we warn about #1 if the -w flag is added,
> see example #3.

If we do change this, we need to make sure that different CVs deriving from the same ‘use constant’ constant need to be exempt from the warning, since the fact that there are two separate CVs is a side effect of the implementation, not a feature per se.  I.e., this should not warn:

package Foo;

require Exporter;
@ISA = Exporter;
@EXPORT_OK = "foo";
use constant "foo" => "oof";
$INC{"Foo.pm"}++;

package main;

use Foo "foo";
$_ = &foo;
use Foo "foo"; # this should not warn


-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=121841



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