This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix for [perl #70910] wrong line number in syntax error message
authorZefram <zefram@fysh.org>
Wed, 9 Dec 2009 22:40:05 +0000 (17:40 -0500)
committerJesse Vincent <jesse@bestpractical.com>
Wed, 9 Dec 2009 22:40:05 +0000 (17:40 -0500)
MANIFEST
t/comp/final_line_num.t [new file with mode: 0644]
toke.c

index a85d318..43e9a49 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4187,6 +4187,7 @@ t/comp/bproto.t                   See if builtins conform to their prototypes
 t/comp/cmdopt.t                        See if command optimization works
 t/comp/colon.t                 See if colons are parsed correctly
 t/comp/decl.t                  See if declarations work
 t/comp/cmdopt.t                        See if command optimization works
 t/comp/colon.t                 See if colons are parsed correctly
 t/comp/decl.t                  See if declarations work
+t/comp/final_line_num.t                See if line numbers are correct at EOF
 t/comp/fold.t                  See if constant folding works
 t/comp/hints.aux               Auxillary file for %^H test
 t/comp/hints.t                 See if %^H works
 t/comp/fold.t                  See if constant folding works
 t/comp/hints.aux               Auxillary file for %^H test
 t/comp/hints.t                 See if %^H works
diff --git a/t/comp/final_line_num.t b/t/comp/final_line_num.t
new file mode 100644 (file)
index 0000000..bb06847
--- /dev/null
@@ -0,0 +1,13 @@
+#!./perl
+
+BEGIN { print "1..1\n"; }
+
+BEGIN { $SIG{__DIE__} = sub {
+       $_[0] =~ /\Asyntax error at [^ ]+ line ([0-9]+), at EOF/ or exit 1;
+       my $error_line_num = $1;
+       print $error_line_num == $last_line_num ? "ok 1\n" : "not ok 1\n";
+       exit 0;
+}; }
+
+# the next line causes a syntax error at end of file, to be caught above
+BEGIN { $last_line_num = __LINE__; } print 1+
diff --git a/toke.c b/toke.c
index d498a34..2ec5f2d 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -4363,7 +4363,8 @@ Perl_yylex(pTHX)
                    PL_doextract = FALSE;
                }
            }
                    PL_doextract = FALSE;
                }
            }
-           incline(s);
+           if (PL_rsfp)
+               incline(s);
        } while (PL_doextract);
        PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
        PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
        } while (PL_doextract);
        PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
        PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);