In perl.git, the branch smoke-me/warning-line-numbers has been updated <http://perl5.git.perl.org/perl.git/commitdiff/1ec929f158d5d615c19bfef500652deed31f4a6d?hp=ee982b091ce3fe08360cc0fff41cd8c3b39c9787>
- Log ----------------------------------------------------------------- commit 1ec929f158d5d615c19bfef500652deed31f4a6d Author: Nicholas Clark <[email protected]> Date: Wed Aug 8 22:59:19 2012 +0200 Test that the warning for "can be 0, test with defined" is for the start. The Perl interpreter is careful to use the line number of the start of the 'Value of %s can be "0"; test with defined()" warning, but there were no tests for this. M op.c M t/lib/warnings/op commit 9db3a59af0b022f356ee3faed5ad6953fa277a4e Author: Nicholas Clark <[email protected]> Date: Wed Aug 8 22:23:29 2012 +0200 Test that the warning for "Found = in conditional" is for the start line. The Perl interpreter is careful to use the line number of the start of the "Found = in conditional", but there were no tests for this. M op.c M t/lib/warnings/op commit 01e5faba36905a00e1779d01eb13b469ebb42d94 Author: Nicholas Clark <[email protected]> Date: Wed Aug 8 16:24:57 2012 +0200 Test that the line number for a "sub redefined" warning is for the start. 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. M op.c M t/lib/warnings/op ----------------------------------------------------------------------- Summary of changes: op.c | 12 ++++++++++-- t/lib/warnings/op | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index 6cfff4f..f61952f 100644 --- a/op.c +++ b/op.c @@ -1085,8 +1085,11 @@ S_scalarboolean(pTHX_ OP *o) if (ckWARN(WARN_SYNTAX)) { 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 the conditional, not the last. */ CopLINE_set(PL_curcop, PL_parser->copline); + } Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Found = in conditional, should be =="); CopLINE_set(PL_curcop, oldline); } @@ -5820,6 +5823,8 @@ S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp) } if (warnop) { const line_t oldline = CopLINE(PL_curcop); + /* This ensures that warnings are reported at the first line + of the construction, not the last. */ CopLINE_set(PL_curcop, PL_parser->copline); Perl_warner(aTHX_ packWARN(WARN_MISC), "Value of %s%s can be \"0\"; test with defined()", @@ -7005,8 +7010,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 a 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 diff --git a/t/lib/warnings/op b/t/lib/warnings/op index 4f33700..eabf8c9 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -106,10 +106,15 @@ __END__ # op.c use warnings 'syntax' ; 1 if $a = 1 ; +1 if $a + = 1 ; no warnings 'syntax' ; 1 if $a = 1 ; +1 if $a + = 1 ; EXPECT Found = in conditional, should be == at - line 3. +Found = in conditional, should be == at - line 4. ######## # op.c use warnings 'syntax' ; @@ -664,28 +669,43 @@ Bareword found in conditional at - line 3. use warnings 'misc' ; open FH, "<abc" ; $x = 1 if $x = <FH> ; +$x = 1 if $x + = <FH> ; no warnings 'misc' ; $x = 1 if $x = <FH> ; +$x = 1 if $x + = <FH> ; EXPECT Value of <HANDLE> construct can be "0"; test with defined() at - line 4. +Value of <HANDLE> construct can be "0"; test with defined() at - line 5. ######## # op.c use warnings 'misc' ; opendir FH, "." ; $x = 1 if $x = readdir FH ; +$x = 1 if $x + = readdir FH ; no warnings 'misc' ; $x = 1 if $x = readdir FH ; +$x = 1 if $x + = readdir FH ; closedir FH ; EXPECT Value of readdir() operator can be "0"; test with defined() at - line 4. +Value of readdir() operator can be "0"; test with defined() at - line 5. ######## # op.c use warnings 'misc' ; $x = 1 if $x = <*> ; +$x = 1 if $x + = <*> ; no warnings 'misc' ; $x = 1 if $x = <*> ; +$x = 1 if $x + = <*> ; EXPECT Value of glob construct can be "0"; test with defined() at - line 3. +Value of glob construct can be "0"; test with defined() at - line 4. ######## # op.c use warnings 'misc' ; @@ -726,10 +746,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' ; -- Perl5 Master Repository
