Skip to content

Add a test for GH#4693, fixed at some point in the past#24388

Open
richardleach wants to merge 1 commit into
Perl:bleadfrom
richardleach:gh4693_test
Open

Add a test for GH#4693, fixed at some point in the past#24388
richardleach wants to merge 1 commit into
Perl:bleadfrom
richardleach:gh4693_test

Conversation

@richardleach
Copy link
Copy Markdown
Contributor

This old ticket pertains to incorrect line numbers when a LOGOP condition can be evaluated at compile time.

if (0) {print "aa";}
elsif (1) {print "bb";}

The condition and untaken branch are freed during compilation. At some point, the surviving optree did not include a COP containing an accurate line number.

It does nowadays, but there doesn't seem to be a dedicated test for it. This commit adds one, plus tests for if() and else() variants.

Closes #4693


  • This set of changes does not require a perldelta entry.

@richardleach richardleach added the defer-next-dev This PR should not be merged yet, but await the next development cycle label Apr 23, 2026
@jkeenan
Copy link
Copy Markdown
Contributor

jkeenan commented Apr 23, 2026

We can bisect to determine when the bug was fixed. Bisecting with the following invocation:

perl Porting/bisect.pl \
--target=miniperl \
--start=v5.20.0 \
--end=v5.22.0 \
--expect-fail \
-- ./miniperl -Ilib /tmp/xgh-4693.pl 0 1

... where the (admittedly unrefined) program being run by miniperl is:

$ cat /tmp/xgh-4693.pl 
eval {
    if ($ARGV[0]) {die "aa";}
    elsif ($ARGV[1]) {die "bb";};
};
my $die_message = "$@";
chomp $die_message;

if ($die_message =~ m/2\.$/) {
    # bug not fixed yet
    print "BAD\n";
    exit 1;
}
elsif ($die_message =~ m/3\.$/) {
    # bug has been fixed
    print "GOOD\n";
    exit 0;
}

... pointed to 51a82aa (v5.21.5-77-g51a82aa9fb) as the commit where behavior changed (in this case, where the bug was fixed):

51a82aa9fb28c58b85d2a2e89872685010ffa91c is the first bad commit
commit 51a82aa9fb28c58b85d2a2e89872685010ffa91c
Author: Father Chrysostomos <sprout@cpan.org>
Date:   Wed Oct 22 19:32:04 2014 -0700
Commit:     Father Chrysostomos <sprout@cpan.org>
CommitDate: Wed Oct 22 19:50:48 2014 -0700

    [perl #122695] Fix line number for else{foo}
    
    where there is no space after the opening brace.
...

@richardleach, there were some tests added in the corrective commit, which may affect where your tests should be placed.

$ git show 51a82aa9fb | grep '^diff'
diff --git a/t/comp/parser.t b/t/comp/parser.t
diff --git a/t/op/runlevel.t b/t/op/runlevel.t
diff --git a/toke.c b/toke.c

This old ticket pertains to incorrect line numbers when a LOGOP condition
can be evaluated at compile time.

```
if (0) {print "aa";}
elsif (1) {print "bb";}
```

The condition and untaken branch are freed during compilation. At some point,
the surviving optree did not include a COP containing an accurate line number.

It does nowadays, but there doesn't seem to be a dedicated test for it. This
commit adds one, plus tests for `if()` and `else()` variants.
@richardleach
Copy link
Copy Markdown
Contributor Author

Thanks @jkeenan. Tests moved to t/op/runlevel.t.

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

Labels

defer-next-dev This PR should not be merged yet, but await the next development cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-B wrong line number after die

3 participants