Strange error: cannot pass immutable value of type 'Int' as inout argument

Why does this error message occur here?


func f(inout v:Int) {}


var x:Int!

x=5

f(&x)

print(x)

The x you're passing into the function is the associated value of the Optional. An overload makes it work. I don't understand the mechanism.


func f(inout v: Int!) {f(&v!)}

The fact that x is an optional is interfering. But given that x would be acceptable both as a function parameter and as lvalue to receive an Int return value, I don't see any obvious reason that Swift shouldn't handle this case automatically. I filed a radar: rdar://23436758.

Strange error: cannot pass immutable value of type 'Int' as inout argument
 
 
Q