Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Confusing behavior relative to existing assigment operators #14

Closed
bchociej opened this issue Feb 19, 2020 · 2 comments
Closed

Confusing behavior relative to existing assigment operators #14

bchociej opened this issue Feb 19, 2020 · 2 comments

Comments

@bchociej
Copy link

bchociej commented Feb 19, 2020

Because the existing assignment operators behave like so:

x += y;
x = x + y;

x -= y;
x = x - y;

// and so on

I would expect the proposed operators to behave in a similar way:

a ||= b;
a = a || b;

a &&= b;
a = a && b;

a ??= b;
a = a ?? b;

I am making no comment on the usefulness of either approach, just that I find the meaning of the operators as proposed to be confusing in light of the behavior of the existing assignment operators.

@rkirsling
Copy link
Member

See #3.

@jridgewell
Copy link
Member

jridgewell commented Feb 19, 2020

#3 deals with this, and we discussed in the latest meeting (see slides 7+).

In particular, this desguaring is over-simplified. (And it whether we run a ?? (a = b) or a = a ?? b is unobservable anyway!) But when it's more complicated, it becomes obvious that += isn't just "copy the left side to the right side". The internal semantics of the operator are different.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants