Skip to content

Conversation

@aenewton
Copy link
Contributor

@aenewton aenewton commented Apr 7, 2017

Per the discussion in the Jira ticket, this PR restores the ability to perform self-assignments if the right side of the expression is wrapped in parentheses:
self.name = (self.name)

Resolves SR-4464.

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a test, since it is a functional change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the right hand side is not an lvalue (e.g., you are assigning the result of a function call) this returns null and you will hit a null pointer deref on the next line. You should unwrap the LoadExpr if one is there, but otherwise keep going.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, @slavapestov. I'll change this and make a test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dyn_casts with unused rvalues should be isas.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be great to leave some comments here explaining the behavior change. It's not obvious why a parenthesized rvalue gets to invoke side effects and a regular assignment doesn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @CodaFi. I'm actually unsure of the reason behind the change. I picked up the ticket because it seemed like a good place to start. It seems to me like the parenthesis would be allowed because it's an explicit indication that you're doing it for the side-effects, but maybe @jrose-apple has a better explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the parens are an "escape hatch" - we need some way to express self-assignment in the case where it's really what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants