Test that the warning for "Found = in conditional" is for the start line.
authorNicholas Clark <nick@ccl4.org>
Wed, 8 Aug 2012 20:23:29 +0000 (22:23 +0200)
committerNicholas Clark <nick@ccl4.org>
Mon, 3 Sep 2012 10:55:23 +0000 (12:55 +0200)
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.

op.c
t/lib/warnings/op

diff --git a/op.c b/op.c
index 744ddd9..9b7b84e 100644 (file)
--- 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);
        }
index bb8a785..b1541b3 100644 (file)
@@ -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' ;