develooper Front page | perl.perl5.porters | Postings from March 2017

Re: [perl #129777] Caller return unexpected info for subs calledfrom condition under while

Thread Previous
From:
Dave Mitchell
Date:
March 21, 2017 12:33
Subject:
Re: [perl #129777] Caller return unexpected info for subs calledfrom condition under while
Message ID:
20170321123156.GB3342@iabyn.com
On Sat, Oct 01, 2016 at 03:48:13AM -0700, KES wrote:
> $ cat test.pl
> #!/usr/bin/env perl
> 
> sub t0 {
>     $l =  0;
>     print "@l\n"   while @l =  (caller $l++)[1,2];
>     1;
> }
> 
> while( t0() && 0 ){
> 
> }
> 
> while( t0() && 1 ){
>     last;
> }
> 
> while( t0() && $i < 2 ){
>     $i++;
> }
> 
> do{
> 
> 
> 
> } while( t0() && 0 );
> 
> $ test.pl
> test.pl 9    # EXPECTED
> test.pl 13   # EXPECTED
> test.pl 17   # EXPECTED
> test.pl 18   # FAIL Here I expect 17
> test.pl 18   # FAIL Here I expect 17
> test.pl 21   # FAIL Here I expect 25
> 
> As you can see LINE information differ between first and followed calls of &t0

Currently perl only records line number information in nextstate ops,
which prefix each statement. The most recent nextstate to be executed
defines the current line number from the point of view of warnings,
caller() etc.

On entry to a while loop, the most-recently-executed nextstate is the one
prefixing the whole while statement. On the second and subsequent
iterations the most-recently-executed nextstate is the one prefixing the
last statement in the body of the loop.

There is talk from time-to-time of recording line-number info per op rather
than only per nextstate op; this would fix a whole bunch of such bugs.

In the meantime I'll attach this ticket to the

    #128666: [META] Line numbers are reported incorrectly

meta-ticket.

-- 
I thought I was wrong once, but I was mistaken.

Thread Previous


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