Skip to content

Commit

Permalink
fix refassign in non-void context
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iabyn committed Jan 22, 2025
1 parent 4b15844 commit 53119a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7516,7 +7516,7 @@ PP(pp_refassign)
in leavesub? */
}
else
rpp_popfree_to_NN(PL_stack_sp - (extra + 1));
rpp_popfree_to_NN(PL_stack_sp - (extra + cBOOL(GIMME_V == G_VOID)));

return NORMAL;
}
Expand Down
13 changes: 12 additions & 1 deletion t/op/lvref.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BEGIN {
set_up_inc("../lib");
}

plan 201;
plan 203;

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

# scalar assignment in scalar context
# GH #22710

{
my @a;
my $ra = ["a", "b"];
my $x = (\@a = $ra);
is \@a, $ra, 'scalar cxt same array';
is $x, $ra, 'scalar cxt return value same array';
}

# Test list assignments in both lval and rval list context
#
# Note that these tests essentially just codify current behaviour.
Expand Down

0 comments on commit 53119a6

Please sign in to comment.