develooper Front page | perl.perl5.porters | Postings from March 2009

Re: Known issue or design decision? Constant sub redefinition ignores "no warnings 'redefine'"

Thread Previous
From:
Elizabeth Mattijsen
Date:
March 26, 2009 08:06
Subject:
Re: Known issue or design decision? Constant sub redefinition ignores "no warnings 'redefine'"
Message ID:
p06240876c5f14a4f4ff7@[10.0.1.191]
At 8:04 AM -0700 3/26/09, Graham Barr wrote:
>On Mar 26, 2009, at 7:15 AM, Dave Mitchell wrote:
>
>>On Thu, Mar 26, 2009 at 09:05:24AM +0100, Bram wrote:
>>>The subject of the patch ('mandatory warning') suggests that it is
>>>intended that the warning can't be disabled. (Which agrees with perldiag
>>>because of the lack of (W redefine))
>>
>>If I were to hazard a guess, I'd say it's because const sub uses are
>>in-lined at compile-time; therefore changing the sub definition later is
>>likely to surprise the user:
>>
>>    sub FOO() { 1 };
>>    *FOO = sub() {2};
>>    print FOO, FOO(), &FOO(), "\n";
>>
>>which prints
>>
>>    112
>
>and
>
>sub FOO () { 1 }
>sub BAR { FOO }
>sub FOO () { 2 }
>print FOO,BAR;
>
>prints 21
>
>It was intentional at the time we added constant subs to give the 
>warning unconditionally
>Graham.

local $SIG{__WARN__} = sub {};

*will* however take care of the warning...  ;-)


Liz

Thread Previous


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