Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

here-docs cause bogus line numbers #12265

Closed
p5pRT opened this issue Jul 10, 2012 · 4 comments
Closed

here-docs cause bogus line numbers #12265

p5pRT opened this issue Jul 10, 2012 · 4 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Jul 10, 2012

Migrated from rt.perl.org#114070 (status was 'resolved')

Searchable as RT114070$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 10, 2012

From @mauke

Created by @mauke

% 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.)

Perl Info

Flags:
    category=core
    severity=medium

This perlbug was built using Perl 5.12.1 - Thu Jun  3 20:09:15 CEST 2010
It is being executed now by  Perl 5.16.0 - Mon May 21 12:24:16 CEST 2012.

Site configuration information for perl 5.16.0:

Configured by mauke at Mon May 21 12:24:16 CEST 2012.

Summary of my perl5 (revision 5 version 16 subversion 0) configuration:
   
  Platform:
    osname=linux, osvers=2.6.38-gentoo-r6, archname=i686-linux
    uname='linux nora 2.6.38-gentoo-r6 #1 preempt sat aug 6 03:05:34 cest 2011 i686 amd athlon(tm) 64 processor 3200+ authenticamd gnulinux '
    config_args='-Dcc=cgcc -Dprefix=/home/mauke/usr/local -Dman1dir=none -Dman3dir=none -Dinc_version_list=none -Doptimize=-O2 -flto'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cgcc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -flto',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.6.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cgcc', ldflags ='-fstack-protector -L/usr/local/lib -O2 -flto'
    libpth=/usr/local/lib /lib/../lib /usr/lib/../lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.14.1.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.14.1'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -flto -L/usr/local/lib -fstack-protector'

Locally applied patches:
    SAVEARGV0 - disable magic open in <ARGV>


@INC for perl 5.16.0:
    /home/mauke/usr/local/lib/perl5/site_perl/5.16.0/i686-linux
    /home/mauke/usr/local/lib/perl5/site_perl/5.16.0
    /home/mauke/usr/local/lib/perl5/5.16.0/i686-linux
    /home/mauke/usr/local/lib/perl5/5.16.0
    .


Environment for perl 5.16.0:
    HOME=/home/mauke
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_COLLATE=POSIX
    LD_LIBRARY_PATH=/home/mauke/usr/local/lib
    LOGDIR (unset)
    PATH=/home/mauke/usr/perlbrew/bin:/home/mauke/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.4.5:/opt/sun-jdk-1.4.2.13/bin:/opt/sun-jdk-1.4.2.13/jre/bin:/opt/sun-jdk-1.4.2.13/jre/javaws:/opt/dmd/bin:/usr/games/bin
    PERLBREW_HOME=/home/mauke/.perlbrew
    PERLBREW_PATH=/home/mauke/usr/perlbrew/bin
    PERLBREW_ROOT=/home/mauke/usr/perlbrew
    PERLBREW_VERSION=0.27
    PERL_BADLANG (unset)
    PERL_UNICODE=SAL
    SHELL=/bin/bash

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 28, 2012

From @cpansprout

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 d794b52 and 78a635d.

--

Father Chrysostomos

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 28, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 28, 2012

@cpansprout - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant