summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2022-03-01 08:09:38 +0000
committerSteve Hay <steve.m.hay@googlemail.com>2022-03-01 08:10:19 +0000
commit30c0a7c19437f19ba1112330f57ffd88b9db1f35 (patch)
treeee7f31e607852cbb67bb5178a6a540711dd3d67d
parent7cdb07a803b7440937d33f8164cef1d1b9163643 (diff)
downloadperl-30c0a7c19437f19ba1112330f57ffd88b9db1f35.tar.gz
scalarseq() should not put an OP_ENTER kid into scalar context (fixes #18855)
(cherry picked from commit 8f4ba78772d3a6dd19ff509eebf2ef05394e742d)
-rw-r--r--op.c9
-rw-r--r--t/op/try.t8
2 files changed, 15 insertions, 2 deletions
diff --git a/op.c b/op.c
index 594d4ee9c3..7006d57e22 100644
--- a/op.c
+++ b/op.c
@@ -2621,8 +2621,13 @@ S_scalarseq(pTHX_ OP *o)
if (type == OP_LINESEQ || type == OP_SCOPE ||
type == OP_LEAVE || type == OP_LEAVETRY)
{
- OP *kid, *sib;
- for (kid = cLISTOPo->op_first; kid; kid = sib) {
+ OP *kid = cLISTOPo->op_first, *sib;
+ if(type == OP_LEAVE) {
+ /* Don't put the OP_ENTER in void context */
+ assert(kid->op_type == OP_ENTER);
+ kid = OpSIBLING(kid);
+ }
+ for (; kid; kid = sib) {
if ((sib = OpSIBLING(kid))
&& ( OpHAS_SIBLING(sib) || sib->op_type != OP_NULL
|| ( sib->op_targ != OP_NEXTSTATE
diff --git a/t/op/try.t b/t/op/try.t
index 32095662f1..9b0fe2b0b5 100644
--- a/t/op/try.t
+++ b/t/op/try.t
@@ -247,6 +247,14 @@ no warnings 'experimental::try';
catch ($e) { 4, 5, 6 }
};
ok(eq_array(\@list, [4, 5, 6]), 'do { try/catch } in list context');
+
+ # Regression test
+ # https://github.com/Perl/perl5/issues/18855
+ $scalar = do {
+ try { die "Oops" }
+ catch ($e) { my $x = 123; "result" }
+ };
+ is($scalar, "result", 'do { try/catch } with multiple statements');
}
# try{} blocks should be invisible to caller()