Skip to content

Commit 8f4ba78

Browse files
committed
scalarseq() should not put an OP_ENTER kid into scalar context (fixes Perl#18855)
1 parent 19a7e82 commit 8f4ba78

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

‎op.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,8 +2622,13 @@ S_voidnonfinal(pTHX_ OP *o)
26222622
if (type == OP_LINESEQ || type == OP_SCOPE ||
26232623
type == OP_LEAVE || type == OP_LEAVETRY)
26242624
{
2625-
OP *kid, *sib;
2626-
for (kid = cLISTOPo->op_first; kid; kid = sib) {
2625+
OP *kid = cLISTOPo->op_first, *sib;
2626+
if(type == OP_LEAVE) {
2627+
/* Don't put the OP_ENTER in void context */
2628+
assert(kid->op_type == OP_ENTER);
2629+
kid = OpSIBLING(kid);
2630+
}
2631+
for (; kid; kid = sib) {
26272632
if ((sib = OpSIBLING(kid))
26282633
&& ( OpHAS_SIBLING(sib) || sib->op_type != OP_NULL
26292634
|| ( sib->op_targ != OP_NEXTSTATE

‎t/op/try.t‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ no warnings 'experimental::try';
247247
catch ($e) { 4, 5, 6 }
248248
};
249249
ok(eq_array(\@list, [4, 5, 6]), 'do { try/catch } in list context');
250+
251+
# Regression test
252+
# https://github.com/Perl/perl5/issues/18855
253+
$scalar = do {
254+
try { die "Oops" }
255+
catch ($e) { my $x = 123; "result" }
256+
};
257+
is($scalar, "result", 'do { try/catch } with multiple statements');
250258
}
251259

252260
# try{} blocks should be invisible to caller()

0 commit comments

Comments
 (0)