Syntax sugar for mutating a rvalue #1395
kyouko-taiga
started this conversation in
Language design
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following program:
The parentheses around
p.copy().unsafe[]
are necessary because we must tell the compiler that we're mutating the result ofunsafe
and not trying to apply the mutating variant ofcopy
(should it be a method bundle).As @dabrahams suggested, we could eliminate these parentheses by allowing
&
to occur after a rvalue. In that case, it would apply to the result of that rvalue rather than the receiver of the first method call in case the expression start with one. For example:p.copy()&.unsafe[].0 = 3
.Beta Was this translation helpful? Give feedback.
All reactions