Swift: inout params should accommodate optionals

Originator:garth
Number:rdar://23436758 Date Originated:06-Nov-2015 01:36 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1
Classification:Enhancement Reproducible:Always
 
The following code produces the error “Cannot pass immutable value of type ‘Int’ as inout argument”:

    func f(inout v:Int) {}
    var x:Int! = 5
    f(&x)

I totally get it. There’s an implicit conversion from Optional<Int> that’s interfering.

However, the code is unambiguous in its intent. Given that Swift happily converts both function parameters and return values to and from optionals, it would make sense for Swift to automatically apply the same type of conversions in this situation.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!