Test that the line number for a "sub redefined" warning is for the start.
authorNicholas Clark <nick@ccl4.org>
Wed, 8 Aug 2012 14:24:57 +0000 (16:24 +0200)
committerNicholas Clark <nick@ccl4.org>
Mon, 3 Sep 2012 10:55:22 +0000 (12:55 +0200)
The Perl interpreter is careful to use the line number of the start of a
subroutine's redefinition for the warning, but there were no tests for this.

op.c
t/lib/warnings/op

diff --git a/op.c b/op.c
index 14ca6fc..744ddd9 100644 (file)
--- a/op.c
+++ b/op.c
@@ -7017,8 +7017,11 @@ Perl_newATTRSUB_flags(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
 #endif
                ) {
                const line_t oldline = CopLINE(PL_curcop);
-               if (PL_parser && PL_parser->copline != NOLINE)
+               if (PL_parser && PL_parser->copline != NOLINE) {
+                        /* This ensures that warnings are reported at the first
+                           line of a redefinition, not the last.  */
                        CopLINE_set(PL_curcop, PL_parser->copline);
+                }
                report_redefined_cv(cSVOPo->op_sv, cv, &const_sv);
                CopLINE_set(PL_curcop, oldline);
 #ifdef PERL_MAD
index 4f33700..bb8a785 100644 (file)
@@ -726,10 +726,15 @@ EXPECT
 use warnings 'redefine' ;
 sub fred {}
 sub fred {}
+sub fred { # warning should be for this line
+}
 no warnings 'redefine' ;
 sub fred {}
+sub fred {
+}
 EXPECT
 Subroutine fred redefined at - line 4.
+Subroutine fred redefined at - line 5.
 ########
 # op.c
 use warnings 'redefine' ;