Skip to content

Commit 2fc16b5

Browse files
iabynjkeenan
authored andcommitted
Deparse: fix 3-arg susbtr_left deparsing
v5.41.7-43-gcdbed2a40e introduced the OP_SUBSTR_LEFT op, which is an optimised version of OP_SUBSTR for when the offset is zero and the replacement string is missing or ''. Unfortunately the deparsing for this OP missed out the closing parenthesis when the replacement string wasn't present; i.e.: substr($lex, 0, 4); deparsed as: substr($lex, 0, 4; The fix is trivial.
1 parent 6752f5c commit 2fc16b5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/B/Deparse.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This is based on the module of the same name by Malcolm Beattie,
88
# but essentially none of his code remains.
99

10-
package B::Deparse 1.83;
10+
package B::Deparse 1.84;
1111
use strict;
1212
use Carp;
1313
use B qw(class main_root main_start main_cv svref_2object opnumber perlstring
@@ -3485,7 +3485,7 @@ sub pp_substr_left {
34853485

34863486
my $val = 'substr(' . $self->deparse($op->first->sibling, $cx)
34873487
. ', 0, ' . $self->deparse($op->first->sibling->sibling->sibling, $cx)
3488-
. ( (($op->private & 7) == 3) ? '' : ", '')" );
3488+
. ( (($op->private & 7) == 3) ? ')' : ", '')" );
34893489

34903490
if ($lex) {
34913491
my $targ = $op->targ;

lib/B/Deparse.t

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,14 @@ print sort(foo('bar'));
18251825
substr(my $a, 0, 0) = (foo(), bar());
18261826
$a++;
18271827
####
1828+
# 3-arg substr (non-chop)
1829+
my $str = 'ABCD';
1830+
my $bbb = substr($str, 1, 1);
1831+
####
1832+
# 3-arg substr (chop)
1833+
my $str = 'ABCD';
1834+
my $aaa = substr($str, 0, 1);
1835+
####
18281836
# 4-arg substr (non-chop)
18291837
my $str = 'ABCD';
18301838
my $bbb = substr($str, 1, 1, '');

0 commit comments

Comments
 (0)