[Swift] Cannot use a () -> Void typed closure literal as the RHS argument of "??"

Originator:AustinZheng
Number:rdar://22016110 Date Originated:27-Jul-2015 01:08 PM
Status:Duplicate of 19237339 Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:
 
Summary:
I can define the following:
var t1 : (() -> Void)? = nil

I can also define the following, with type inferred as () -> ():
var t1a = { print("blah") }

However, trying to define the following gives me an error:
var t2 = t1 ?? { print("blah") }

The error is: "Function produces expected type '()', did you mean to call it with '()'?".

Adding the explicit type annotation '() -> Void' to t2's declaration does not solve the problem. Neither does writing out the closure's signature as follows:

var t2 : () -> Void = t1 ?? { () -> Void in
  print("blah")
}

Version:
Xcode 7b4 (7A165t), OS X 10.10.4 (14E46)

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!