Skip to content

Commit ebfc9d5

Browse files
committed
subroutine redefinitions made with local() shouldn't warn
The following code will no longer warn: use warnings 'redefine'; sub foo {} local *foo = sub{}; The main purpose of local() is to temporarily redefine stuff, so it doesn't make sense to warn about it.
1 parent 14ec34b commit ebfc9d5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

pod/perldelta.pod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ XXX Changes (i.e. rewording) of diagnostic messages go here
218218

219219
=item *
220220

221-
XXX Describe change here
221+
L<Subroutine %s redefined|perldiag/"Subroutine %s redefined">
222+
223+
Localized subroutine redefinitions no longer trigger this warning.
222224

223225
=back
224226

sv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4187,7 +4187,7 @@ Perl_gv_setref(pTHX_ SV *const dsv, SV *const ssv)
41874187
(CvROOT(cv) || CvXSUB(cv)) &&
41884188
/* redundant check that avoids creating the extra SV
41894189
most of the time: */
4190-
(CvCONST(cv) || ckWARN(WARN_REDEFINE)))
4190+
(CvCONST(cv) || (ckWARN(WARN_REDEFINE) && !intro)))
41914191
{
41924192
SV * const new_const_sv =
41934193
CvCONST((const CV *)sref)

t/lib/warnings/sv

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,18 @@ undef *Foo::;
437437
*Foo::f =sub {};
438438
EXPECT
439439
Subroutine f redefined at - line 5.
440+
########
441+
# sv.c
442+
use warnings 'redefine';
443+
sub fred { 1 }
444+
sub barney() { 2 }
445+
sub wilma() { 3 }
446+
# local redefines of subs shouldn't warn...
447+
local *fred = sub {};
448+
local(*fred) = sub {};
449+
# ...unless they're constant
450+
local *barney = \&fred;
451+
local(*wilma) = \&fred;
452+
EXPECT
453+
Constant subroutine main::barney redefined at - line 10.
454+
Constant subroutine main::wilma redefined at - line 11.

0 commit comments

Comments
 (0)