Skip to content

Commit 53119a6

Browse files
committed
fix refassign in non-void context
GH #22710 The experimental refassign feature, \@A = $aref, which allows an array/hash etc to be aliased rather than copied, got broken in rvalue non-void context by v5.39.5-56-g604c0355d2. So in something like my $x = (\@A = $aref); the stack was underflowing. This is because previously pp_refassign() would leave its RH argument on the stack when returning, while my commit above made it always pop the argument off the stack. This commit makes it only pop the arg in void context.
1 parent 4b15844 commit 53119a6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7516,7 +7516,7 @@ PP(pp_refassign)
75167516
in leavesub? */
75177517
}
75187518
else
7519-
rpp_popfree_to_NN(PL_stack_sp - (extra + 1));
7519+
rpp_popfree_to_NN(PL_stack_sp - (extra + cBOOL(GIMME_V == G_VOID)));
75207520

75217521
return NORMAL;
75227522
}

t/op/lvref.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BEGIN {
55
set_up_inc("../lib");
66
}
77

8-
plan 201;
8+
plan 203;
99

1010
eval '\$x = \$y';
1111
like $@, qr/^Experimental aliasing via reference not enabled/,
@@ -225,6 +225,17 @@ package ArrayTest {
225225
is \@i, $old, '(\local @a) unwound';
226226
}
227227

228+
# scalar assignment in scalar context
229+
# GH #22710
230+
231+
{
232+
my @a;
233+
my $ra = ["a", "b"];
234+
my $x = (\@a = $ra);
235+
is \@a, $ra, 'scalar cxt same array';
236+
is $x, $ra, 'scalar cxt return value same array';
237+
}
238+
228239
# Test list assignments in both lval and rval list context
229240
#
230241
# Note that these tests essentially just codify current behaviour.

0 commit comments

Comments
 (0)