Deconstructing assignment and reader/modify/write operands

# Oliver Hunt (6 years ago)

I am reading the spec and it looks (to me at least) like we expect [a,b,c] += [1,2,3] to be equivalent to a+=1; b+=2; c+=3 — is that correct or have i misread something?

# Allen Wirfs-Brock (6 years ago)

No, see

Destructuring is only checked for in the LHS = RHS case.

The LHS AssignmentOperator RHS case is just like ES5 and doesn't do any destructuring.

# Brendan Eich (6 years ago)

Oliver may be asking "why?" The reductiionistic answer is because L += R is evaluated as if by L = L + R but with L evaluated to a Reference once only.

The deeper question (if I may stand in for Oliver) is why wouldn't we want some nicer new semantic for [a, b] += [c, d] -- a "parallel add-and-assign." We could do that, but it would deviate from the straightforward meaning of the assignment operators composed with destructuring, by quite a bit.

When composing two things leads to an unexpected result, there's a smell. It could be handy, but it's probably better off done with a distinct special form.

# Oliver Hunt (6 years ago)

I'll try to rephrase:

As I read the spec this is not a syntax error, and so gets delayed to runtime. Given that we're already doing work to determine whether we should be destructuring (which results in different runtime semantics), it seems we should promote (demote?) <deconstructing lhs> <rwm operator> <expression> to a syntax error -- it seems like it would be an easy typo to make so detecting it earlier would seem a plus.

FWIW I'm not sure I agree with brendan on this idea being a misfeature, but I think we really should try to make it at least an early error.

# Allen Wirfs-Brock (6 years ago)

It is an early error, which is specified via the "IsValidSinpleAssigment" based Early Error rules in

This follows from the ES5 requirement in clause 16: that says "Attempts to PutValue on any value for which early determination can be made that the value is not a Reference" [is an early error].

IsValidSimpleAssignmentTarget is a formalization of that "early determination".