Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ priorities and future plans.
nested signature calls, and keep Test2 negation accessors visible to the
interpreter.
- Preserve call-site package information in generated subroutine frames so Moo destructor croaks report the correct source location.
- Preserve generated-method call-site packages while Carp selects croak locations through eval wrappers.
- Pass the Image::ExifTool 13.55 test suite by preserving escaped
transliteration ranges and numeric string flags, and allowing valid nested
conditional `goto` targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5825,9 +5825,7 @@ public static RuntimeList callerWithSub(RuntimeList args, int ctx, RuntimeScalar
boolean carpTrustedFrame = isCarpStackActive() && reportedCode != null
&& isCarpTrustedCallerPackage(reportedCode.packageName);
if ((reportedCode != null && "DESTROY".equals(reportedCode.subName))
|| (isCarpStackActive()
&& isDestroyActiveOnStack()
&& !carpTrustedFrame)) {
|| (isCarpStackActive() && !carpTrustedFrame)) {
String callSitePackage = getCallerPackageAtCallerFrame(trackedActiveCodeFrame);
if (callSitePackage != null && !callSitePackage.isEmpty()) {
pkg = callSitePackage;
Expand Down
45 changes: 45 additions & 0 deletions src/test/resources/unit/carp_moo_eval_wrapper_location.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use strict;
use warnings;
use Test::More;
use Carp ();

if (!eval { require Moo; 1 }) {
plan skip_all => 'Moo is required for the eval-wrapper croak location regression';
}

my $package = 'CarpMooEvalWrapperLocation';
my $code = <<'MOO_CODE';
use Moo;
has attr => (is => 'rwp', lazy => 1, default => 1);
my $obj = $PACKAGE->new;
package Elsewhere;
$obj->attr(5);
MOO_CODE
$code =~ s/\$PACKAGE/$package/g;

my $source = $code;
$source =~ s/\n\z//;
my $expected_line = 1 + ($source =~ tr/\n//);
my $test_sub = eval(
"sub {\n"
. "package $package;\n"
. "#line 1 CarpMooEvalWrapperLocationTest\n"
. $code
. "\n}\n"
);
BAIL_OUT("could not compile Moo croak location reproducer: $@") unless $test_sub;

my $error;
{
local $@;
eval { $test_sub->(); 1 };
$error = $@;
}

like(
$error,
qr/at CarpMooEvalWrapperLocationTest line \Q$expected_line\E\.?\n?\z/s,
'Carp::croak reports the generated method call site through the eval wrapper',
) or diag("error: $error");

done_testing();
Loading