-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
semantics of assigning to a?.x #9
Comments
Since |
Current spec says: Evaluation of an assignment a of the form e1?.v = e2 is equivalent to the evaluation of the expression ((x) => x == null?null : x.v = e2)(e1). The static type of a is the static type of e2. Let T be the static type of e1 and let y be a fresh variable of type T. Exactly the same static warnings that would be In other words, e2 is not evaluated if e1 is null. This is consistent with our treatment of method arguments in general. Basically, if the target is null, nothing happens. Very similar to writing (a = e1) != null ? a.x = e2 : null which is presumably what you would have had to write before this worthy construct was introduced. |
👍 |
great, thanks for the clarification! |
What should we expect with the
?.
operator when used with assignments:My current expectation is that this should be equivalent to:
(both expressions are evaluated once, exp2 is evaluated even when exp1 is null)
The text was updated successfully, but these errors were encountered: