Branch: refs/heads/blead
Home: https://github.com/Perl/perl5
Commit: 71222285a385b8ad7ec333bdb281bffba71da716
https://github.com/Perl/perl5/commit/71222285a385b8ad7ec333bdb281bffba71da716
Author: Richard Leach <[email protected]>
Date: 2026-07-20 (Mon, 20 Jul 2026)
Changed paths:
M t/op/caller.t
M util.c
Log Message:
-----------
Perl_closest_cop - traverse LOGOPs for more accurate line numbers
`Perl_closest_cop` attempts to find the COP closest to a supplied
OP*, from which source code file name and line number information
is typically retrieved. Other than recursive calls to itself, this
function's main callers are `pp_caller` and `Perl_mess_sv`.
The function checks for `ex-nextstate` COPs that are more relevant
than the supplied live COP, but prior to this commit it returned
early rather than walking common LOGOP optrees. Branches within
those trees that don't have a full OP_ENTER/OP_LEAVE scoping pair
will instead have an OP_SCOPE followed by an OP_NEXTSTATE - and
that COP gets nulled out during compilation.
This is one reason why wildly inaccurate line numbers might be
returned in warnings or error messages, as in this example
adapted from GH #16872:
```
use strict; use warnings;
sub u(_) { defined($_[0]) ? $_[0] : "undef" }
sub f { warn((join ", ", map{u} (caller(0))), "\n"); }
use Carp;
my $bad = 1;
if (0) { # <-- The live COP is around here
#
#
# millions of lines of spagetti code
#
#
}
elsif ($bad) {
# <-- The ex-nextstate COP is around here
# my $x; #un-comment and the problem goes away
confess("HERE WE ARE");
}
```
Commit: 4105c196494d62d0d501b87387dc2778c4d8b776
https://github.com/Perl/perl5/commit/4105c196494d62d0d501b87387dc2778c4d8b776
Author: Richard Leach <[email protected]>
Date: 2026-07-20 (Mon, 20 Jul 2026)
Changed paths:
M t/op/caller.t
M util.c
Log Message:
-----------
Perl_closest_caller - continue traversing past OP_LINESEQ
This also improves the output for code that looks like _muddle.pl_
shown in GH #4125:
```
use strict;
use warnings;
use Carp;
sub t1 {
Carp::confess("t1") if $ARGV[0] == 1;
}
sub t2 {
Carp::confess("t2") if $ARGV[0] == 2;
}
sub t3 {
Carp::confess("t3") if $ARGV[0] == 3;
}
if (t1) {
} elsif (t2) {
} elsif (t3) {
}
```
Instead of:
```
$ perl muddle.pl 1
t1 at muddle.pl line 6.
main::t1() called at muddle.pl line 16
$ perl muddle.pl 2
t2 at muddle.pl line 9.
main::t2() called at muddle.pl line 16
$ perl muddle.pl 3
t3 at muddle.pl line 12.
main::t3() called at muddle.pl line 16
```
we now get:
```
$ perl muddle.pl 1
t1 at muddle.pl line 6.
main::t1() called at muddle.pl line 16
$ perl muddle.pl 2
t2 at muddle.pl line 9.
main::t2() called at muddle.pl line 18
$ perl muddle.pl 3
t3 at muddle.pl line 12.
main::t3() called at muddle.pl line 20
```
This commit does not improve the output of other two code snippets in
GH #4125, where interactions between inline `sub{}` declarations are
a factor.
Compare: https://github.com/Perl/perl5/compare/0c2bcc836a37...4105c196494d
To unsubscribe from these emails, change your notification settings at
https://github.com/Perl/perl5/settings/notifications