diff options
author | Matthew Horsfall <wolfsage@gmail.com> | 2021-06-10 15:58:47 -0400 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2022-02-27 11:24:18 +0000 |
commit | 884ea8d33334dc55e34370b4fbb79fb7ec15ee33 (patch) | |
tree | 10a3231745c185202ccca7ce83cb0c4fcb31be7a | |
parent | 5c6c3034a5f1cc9519c9c73b0edcdc45a27dd394 (diff) | |
download | perl-884ea8d33334dc55e34370b4fbb79fb7ec15ee33.tar.gz |
B::Deparse: Handle try/catch when catch has an ENTER/LEAVE pair
(cherry picked from commit 846e32ebef2bd121948a426b6a6ca7d48e3a0a7a)
-rw-r--r-- | lib/B/Deparse.pm | 10 | ||||
-rw-r--r-- | lib/B/Deparse.t | 9 |
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm index 67147f12dd..10c30e8611 100644 --- a/lib/B/Deparse.pm +++ b/lib/B/Deparse.pm @@ -52,7 +52,7 @@ use B qw(class main_root main_start main_cv svref_2object opnumber perlstring MDEREF_SHIFT ); -$VERSION = '1.56'; +$VERSION = '1.57'; use strict; our $AUTOLOAD; use warnings (); @@ -4072,11 +4072,15 @@ sub pp_leavetrycatch { $catch->name eq "catch" or die "Expected catch as third child of leavetrycatch"; my $catchblock = $catch->first->sibling; - $catchblock->name eq "scope" or die "Expected scope as second child of catch"; + my $name = $catchblock->name; + unless ($name eq "scope" || $name eq "leave") { + die "Expected scope or leave as second child of catch, got $name instead"; + } my $trycode = scopeop(0, $self, $tryblock); my $catchvar = $self->padname($catch->targ); - my $catchcode = scopeop(0, $self, $catchblock); + my $catchcode = $name eq 'scope' ? scopeop(0, $self, $catchblock) + : scopeop(1, $self, $catchblock); return "try {\n\t$trycode\n\b}\n" . "catch($catchvar) {\n\t$catchcode\n\b}\cK"; diff --git a/lib/B/Deparse.t b/lib/B/Deparse.t index 24eb445041..fd4d63c779 100644 --- a/lib/B/Deparse.t +++ b/lib/B/Deparse.t @@ -3171,3 +3171,12 @@ try { catch($var) { SECOND(); } +#### +# CONTEXT use feature 'try'; no warnings 'experimental::try'; +try { + FIRST(); +} +catch($var) { + my $x; + SECOND(); +} |