fix line numbers in multi-line s///
authorDavid Mitchell <davem@iabyn.com>
Wed, 7 Mar 2018 09:27:26 +0000 (09:27 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 7 Mar 2018 09:27:26 +0000 (09:27 +0000)
my commit v5.25.6-230-g6432a58, "Eliminate SVrepl_EVAL and SvEVALED()",
introduced a regression: __LINE__ no longer took account of multiple
lines in the s///.

Now fixed.

Spotted by Abigail.

t/re/subst.t
toke.c

index b9b9939..dd62e95 100644 (file)
@@ -11,7 +11,7 @@ BEGIN {
     require './loc_tools.pl';
 }
 
-plan(tests => 275);
+plan(tests => 276);
 
 $_ = 'david';
 $a = s/david/rules/r;
@@ -1163,6 +1163,16 @@ __EOF__
     pass("RT #130188");
 }
 
+# RT #131930
+# a multi-line s/// wasn't resetting the cop_line correctly
+{
+    my $l0 = __LINE__;
+    my $s = "a";
+    $s =~ s[a]
+           [b];
+    my $lines = __LINE__ - $l0;
+    is $lines, 4, "RT #131930";
+}
 
 
 
diff --git a/toke.c b/toke.c
index 9dbad98..0ef3341 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9884,7 +9884,7 @@ S_scan_subst(pTHX_ char *start)
          * the NVX field indicates how many src code lines the replacement
          * spreads over */
         sv_upgrade(PL_parser->lex_sub_repl, SVt_PVNV);
-        ((XPVNV*)SvANY(PL_parser->lex_sub_repl))->xnv_u.xnv_lines = 0;
+        ((XPVNV*)SvANY(PL_parser->lex_sub_repl))->xnv_u.xnv_lines = linediff;
         ((XPVIV*)SvANY(PL_parser->lex_sub_repl))->xiv_u.xivu_eval_seen =
                                                                     cBOOL(es);
     }