diff options
-rw-r--r-- | op.c | 10 | ||||
-rw-r--r-- | t/op/aassign.t | 10 |
2 files changed, 17 insertions, 3 deletions
@@ -15724,11 +15724,15 @@ S_aassign_scan(pTHX_ OP* o, bool rhs, int *scalars_p) goto do_next; case OP_UNDEF: - /* undef counts as a scalar on the RHS: - * (undef, $x) = ...; # only 1 scalar on LHS: always safe + /* undef on LHS following a var is significant, e.g. + * my $x = 1; + * @a = (($x, undef) = (2 => $x)); + * # @a shoul be (2,1) not (2,2) + * + * undef on RHS counts as a scalar: * ($x, $y) = (undef, $x); # 2 scalars on RHS: unsafe */ - if (rhs) + if ((!rhs && *scalars_p) || rhs) (*scalars_p)++; flags = AAS_SAFE_SCALAR; break; diff --git a/t/op/aassign.t b/t/op/aassign.t index ed904adc62..9128f9fd98 100644 --- a/t/op/aassign.t +++ b/t/op/aassign.t @@ -594,4 +594,14 @@ SKIP: { is ($fill, 2, "RT #130132 array 2"); } +{ + # GH #17816 + # don't use the "1-arg on LHS can't be common" optimisation + # when there are undef's there + my $x = 1; + my @a = (($x, undef) = (2 => $x)); + is("@a", "2 1", "GH #17816"); +} + + done_testing(); |