Swift error reporting + code readability with single-line block
| Originator: | raphael | ||
| Number: | rdar://17357044 | Date Originated: | 18-Jun-2014 10:49 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6 Beta2 |
| Classification: | Enhancement | Reproducible: | Not Applicable |
The following very simple code generates an error with Swift:
====
let handler: (() -> ())? = {
println("test")
}
let handler2: () -> () = {
handler?()
}
====
Error: Cannot convert the expression's type '() -> $T0' to type '$T4'
This is because handler2 returns Void per its type, but is returning Void? per its code (single line closure). Got it.
Isn't this construct very counter intuitive? (Not just talking of the error message.)
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!