Fix line nums when multiline ${expr} spans here-doc
authorFather Chrysostomos <sprout@cpan.org>
Fri, 20 Sep 2013 07:50:54 +0000 (00:50 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 20 Sep 2013 08:19:07 +0000 (01:19 -0700)
<<end . ${

end
"bar"};
warn __LINE__ # 3, not 5

This was caused by commit a49b10d0a, which make scan_ident in toke.c
reallocate the parser’s current line buffer (SvPVX(PL_linestr)) to
search for whitespace surrounding an identifier.

In case there is an arbitrary expression, it temporarily records the
line number and resets it at the end if that turns out to be the case.
However, it was not resetting PL_parser->herelines, which records how
many line numbers to skip when next incrementing it (to skip past
here-doc bodies).

So save and restore that value, too.

t/comp/parser.t
toke.c

index 6578c74..8fd7e85 100644 (file)
@@ -8,7 +8,7 @@ BEGIN {
     chdir 't';
 }
 
-print "1..167\n";
+print "1..168\n";
 
 sub failed {
     my ($got, $expected, $name) = @_;
@@ -634,5 +634,13 @@ ${;
 END
 check_line(627, 'line number after heredoc containing #line');
 
+#line 638
+<<ENE . ${
+
+ENE
+"bar"};
+check_line(642, 'line number after ${expr} surrounding heredoc body');
+
+
 __END__
 # Don't add new tests HERE. See note above
diff --git a/toke.c b/toke.c
index 14d9b98..257d69b 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -9371,6 +9371,7 @@ STATIC char *
 S_scan_ident(pTHX_ char *s, char *dest, STRLEN destlen, I32 ck_uni)
 {
     dVAR;
+    I32 herelines = PL_parser->herelines;
     SSize_t bracket = -1;
     char funny = *s++;
     char *d = dest;
@@ -9552,6 +9553,7 @@ S_scan_ident(pTHX_ char *s, char *dest, STRLEN destlen, I32 ck_uni)
                state such that the next thing to process is the opening { and */
            s = SvPVX(PL_linestr) + bracket; /* let the parser handle it */
             CopLINE_set(PL_curcop, orig_copline);
+            PL_parser->herelines = herelines;
            *dest = '\0';
        }
     }