This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Warn by default for constant my sub redefinition
authorFather Chrysostomos <sprout@cpan.org>
Sat, 24 Nov 2012 07:44:49 +0000 (23:44 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 24 Nov 2012 15:35:50 +0000 (07:35 -0800)
I apparently never had this working and never tested it either.

I was checking whether the new sub was a constant, rather than the one
it was clobbering.

op.c
t/lib/warnings/op

diff --git a/op.c b/op.c
index 0e287e1..871982c 100644 (file)
--- a/op.c
+++ b/op.c
@@ -7056,7 +7056,7 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
            else {
                /* redundant check that avoids creating the extra SV
                   most of the time: */
-               if (const_sv || ckWARN(WARN_REDEFINE)) {
+               if (CvCONST(cv) || ckWARN(WARN_REDEFINE)) {
                    const line_t oldline = CopLINE(PL_curcop);
                    SV *noamp = sv_2mortal(newSVpvn_utf8(
                                    PadnamePV(name)+1,PadnameLEN(name)-1,
index 52b35b6..35cfb17 100644 (file)
@@ -778,6 +778,25 @@ EXPECT
 Constant subroutine main::fred redefined at - line 3.
 ########
 # op.c
+use feature "lexical_subs", "state";
+my sub fred () { 1 }
+sub fred { 2 };
+my sub george { 1 }
+sub george () { 2 } # should *not* produce redef warnings by default
+state sub phred () { 1 }
+sub phred { 2 };
+state sub jorge { 1 }
+sub jorge () { 2 } # should *not* produce redef warnings by default
+EXPECT
+The lexical_subs feature is experimental at - line 2.
+Prototype mismatch: sub fred () vs none at - line 4.
+Constant subroutine fred redefined at - line 4.
+Prototype mismatch: sub george: none vs () at - line 6.
+Prototype mismatch: sub phred () vs none at - line 8.
+Constant subroutine phred redefined at - line 8.
+Prototype mismatch: sub jorge: none vs () at - line 10.
+########
+# op.c
 no warnings 'redefine' ;
 sub fred () { 1 }
 sub fred () { 2 }