This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove & from redef warnings for lex subs
authorFather Chrysostomos <sprout@cpan.org>
Mon, 9 Jul 2012 20:00:28 +0000 (13:00 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 16 Sep 2012 05:45:02 +0000 (22:45 -0700)
This is just for consistency with package subs.

op.c
t/cmd/lexsub.t

diff --git a/op.c b/op.c
index 705374b..da93b14 100644 (file)
--- a/op.c
+++ b/op.c
@@ -6976,11 +6976,19 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
                goto done;
            }
            else {
-               const line_t oldline = CopLINE(PL_curcop);
-               if (PL_parser && PL_parser->copline != NOLINE)
+               /* redundant check that avoids creating the extra SV
+                  most of the time: */
+               if (const_sv || ckWARN(WARN_REDEFINE)) {
+                   const line_t oldline = CopLINE(PL_curcop);
+                   SV *noamp = sv_2mortal(newSVpvn_utf8(
+                                   PadnamePV(name)+1,PadnameLEN(name)-1,
+                                    PadnameUTF8(name)
+                               ));
+                   if (PL_parser && PL_parser->copline != NOLINE)
                        CopLINE_set(PL_curcop, PL_parser->copline);
-               report_redefined_cv(name, cv, &const_sv);
-               CopLINE_set(PL_curcop, oldline);
+                   report_redefined_cv(noamp, cv, &const_sv);
+                   CopLINE_set(PL_curcop, oldline);
+               }
 #ifdef PERL_MAD
                if (!PL_minus_c)        /* keep old one around for madskills */
 #endif
index ffabbd1..84abff0 100644 (file)
@@ -269,7 +269,6 @@ sub make_anon_with_state_sub{
   state $w;
   local $SIG{__WARN__} = sub { $w .= shift };
   eval "#line 56 pygpyf\nsub redef {}";
-on;
   is $w, "Subroutine redef redefined at pygpyf line 56.\n",
          "sub redefinition warnings from state subs";
 }