While tightening up tok::amp_prefix
parsing, I noticed that explicit inout
parameters are allowed on binary operators (i.e. ptr == &val
). Out of curiosity, is this a feature that has aged well? If we didn't have it, would we add it today?
Did you see this thread? I think it's discussing some of the same issues.
I'm aware of that. I'm curious about the general case.
Don’t all the inplace operators need that? e.g. +=
, *=
, etc
The in-place operators have special syntax/rules that allow for implicit inout semantics on the lefthand side. I'm just asking about whether explicit inout parameters (via prefix &
) on binary operators have aged well or not in light of the "inout-to-UnsafePointer conversion" discussion.
Does it actually need an explicit &
? I have used it once and it worked without asking me to use &
. I just tried a trivial example, and it didn't let me put &
. (Using Xcode 9.3)
func ~> (lhs: Int, rhs: inout Int) -> Int {
rhs += 1
return lhs*rhs
}
var y = 3
let z = 2 ~> y
let t = 2 ~> &y // error: '&' can only appear immediately in a call argument list
Well that's embarrassing. I apparently haven't looked at the attributes on the assignment operators in a long time. One used to be required to use @assignment
for the implicit inout
behavior, but not anymore. I think I answered my own question now. Thanks.