develooper Front page | perl.perl5.porters | Postings from August 2012

[perl #114070] here-docs cause bogus line numbers

From:
Father Chrysostomos via RT
Date:
August 27, 2012 23:27
Subject:
[perl #114070] here-docs cause bogus line numbers
Message ID:
rt-3.6.HEAD-11172-1346135250-1501.114070-15-0@perl.org
On Tue Jul 10 15:08:27 2012, l.mai@web.de wrote:
> % cat bug.pl
> #!perl
> use warnings;
> use strict;
> 
> use Test::More tests => 10;
> 
> sub lineno {
>         my ($unique_marker) = @_;
>         seek DATA, 0, 0 or die "seek: $!";
>         my $n = 0;
>         while (my $line = readline DATA) {
>                 $n++;
>                 return $n if $line =~ /\Q$unique_marker/;
>         }
>         undef
> }
> 
> sub test_line {
>         my ($unique_marker) = @_;
>         my $perl_line = (caller)[2];
>         is $perl_line, lineno($unique_marker), qq(line with
>    "$unique_marker");
> }
> 
> 
> #line 26
> test_line '.{A1}.'; $_ = <<EOT; test_line '.{A2}.';
> hi
> EOT
> test_line '.{A3}.';
> 
> 
> # This test is the main reason for the #line annotations. It corrupts
>    line
> # numbers for all following code.
> #line 35
> test_line '.{B1}.'; $_ =~ s/^/${\<<EOT}/; test_line '.{B2}.';
> hi
> EOT
> test_line '.{B3}.';
> 
> 
> #line 42
> test_line '.{C1}.'; is "@{[<<EOT x 0]}", ''; test_line '.{C2}.';
> hi
> EOT
> test_line '.{C3}.';
> 
> __DATA__
> 
> % prove bug.pl
> bug.pl .. 1/10
> #   Failed test 'line with ".{A2}."'
> #   at bug.pl line 21.
> #          got: '28'
> #     expected: '26'
> 
> #   Failed test 'line with ".{B3}."'
> #   at bug.pl line 21.
> #          got: '36'
> #     expected: '38'
> 
> #   Failed test 'line with ".{C3}."'
> #   at bug.pl line 21.
> #          got: '43'
> #     expected: '45'
> # Looks like you failed 3 tests of 10.
> bug.pl .. Dubious, test returned 3 (wstat 768, 0x300)
> Failed 3/10 subtests
> 
> Test Summary Report
> -------------------
> bug.pl (Wstat: 768 Tests: 10 Failed: 3)
>   Failed tests:  2, 6, 10
>   Non-zero exit status: 3
> Files=1, Tests=10,  0 wallclock secs ( 0.03 usr  0.01 sys +  0.02 cusr
>    0.00 csys =  0.06 CPU)
> Result: FAIL
> 
> 
> There are two bugs here:
> 
>  - (minor): perl records the wrong line number for any statement that
>    starts in
>             the same line as a here-doc.
> 
>  - (major): The ${\<<EOT} construct makes perl record wrong line
>    numbers for all
>             following code in the same file. (Debugging that one is
>    fun.)

I fixed those in commit 83944c0.  In doing so I made line numbers inside
here-docs worse than before (they were already off by one).  So I fixed
that in d794b5224 and 78a635d.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=114070



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About