break;
case OP_UNDEF:
+ /* undef counts as a scalar on the RHS:
+ * (undef, $x) = ...; # only 1 scalar on LHS: always safe
+ * ($x, $y) = (undef, $x); # 2 scalars on RHS: unsafe
+ */
+ if (rhs)
+ (*scalars_p)++;
+ flags = AAS_SAFE_SCALAR;
+ break;
+
case OP_PUSHMARK:
case OP_STUB:
/* these are all no-ops; they don't push a potentially common SV
|| !r /* .... = (); */
|| !(l & ~AAS_SAFE_SCALAR) /* (undef, pos()) = ...; */
|| !(r & ~AAS_SAFE_SCALAR) /* ... = (1,2,length,undef); */
- || (lscalars < 2) /* ($x) = ... */
+ || (lscalars < 2) /* ($x, undef) = ... */
) {
NOOP; /* always safe */
}
/* ... = ($x)
* may have to handle aggregate on LHS, but we can't
- * have common scalars*/
+ * have common scalars. */
if (rscalars < 2)
o->op_private &=
~(OPpASSIGN_COMMON_SCALAR|OPpASSIGN_COMMON_RC1);
}
+{
+ my $x = 1;
+ my $y = 2;
+ ($x,$y) = (undef, $x);
+ is($x, undef, 'single scalar on RHS, but two on LHS: x');
+ is($y, 1, 'single scalar on RHS, but two on LHS: y');
+}
+
done_testing();
'expr::aassign::2l_1l' => {
desc => 'single lexical RHS',
setup => 'my $x = 1;',
+ code => '($x,$x) = ($x)',
+ },
+ 'expr::aassign::2l_1ul' => {
+ desc => 'undef and single lexical RHS',
+ setup => 'my $x = 1;',
code => '($x,$x) = (undef, $x)',
},