From b2362f9ce4a402f311f6b7a96d97bbe9569e2f54 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Wed, 22 Nov 2017 12:14:42 +0000 Subject: [PATCH] Don't Deparse "${$}abc" as "$$abc" This fixes ./TEST -deparse op/stat.t This only fixes multiconcat - in theory concat suffers from the same bug, although in practice any concat expression involving at least one constant string will be upgraded to multiconcat. --- lib/B/Deparse.pm | 8 ++++++-- lib/B/Deparse.t | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/B/Deparse.pm b/lib/B/Deparse.pm index 0cbb890..b19b40f 100644 --- a/lib/B/Deparse.pm +++ b/lib/B/Deparse.pm @@ -4405,8 +4405,12 @@ sub do_multiconcat { # "foo=$foo bar=$bar " my $not_first; while (@consts) { - $rhs = dq_disambiguate($rhs, $self->dq(shift(@kids), 18)) - if $not_first; + if ($not_first) { + my $s = $self->dq(shift(@kids), 18); + # don't deparse "a${$}b" as "a$$b" + $s = '${$}' if $s eq '$$'; + $rhs = dq_disambiguate($rhs, $s); + } $not_first = 1; my $c = shift @consts; if (defined $c) { diff --git a/lib/B/Deparse.t b/lib/B/Deparse.t index ca1bdb4..83e46e8 100644 --- a/lib/B/Deparse.t +++ b/lib/B/Deparse.t @@ -2983,3 +2983,8 @@ $res = CORE::keys(%$r2) / 2 - 1; my($a, $b); $b = $a . $a . $a; (($a .= $a) .= $a) .= $a; +#### +# multiconcat: $$ within string +my($a, $x); +$x = "${$}abc"; +$x = "\$$a"; -- 1.8.3.1