Bad error message for implicitly returned Optional<Void> from closure.
| Originator: | brian.nickel | ||
| Number: | rdar://18986240 | Date Originated: | 14-Nov-2014 12:21 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.1 |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
The following line has an implicit return of Int(10) and generates an error message of "'Int' is not convertible to 'Void'".
var caller1 = { () -> Void in 5 + 5 }
That's reasonable.
The following method has an implicit return of Void and doesn't generate an error:
var x:[Int]?
var caller2 = { () -> Void in x!.append(5) }
This third method has an implicit return type of Optional<Void> and should generate an error message of "'Void?' is not convertible to 'Void'".
var x:[Int]?
var caller3 = { () -> Void in x?.append(5) }
Instead it returns a cryptic error message:
Cannot convert the expression's type '() -> Void to type Int'
It seems like the parser may be trying to turn it into something else because the following two methods compile once the return type becomes Void:
var x:[Int]?
var caller3ret = { () -> Void in x?.append(5); return }
var caller3bang = { () -> Void in (x?.append(5))! }
Steps to Reproduce:
Paste the following into a storyboard. Gawk at the resulting message:
var x:[Int]?
var caller3 = { () -> Void in x?.append(5) }
Expected Results:
A reasonable error message. Maybe something special since Void? is not a common type.
Actual Results:
Weird error message:
Cannot convert the expression's type '() -> Void to type Int'
Version:
Yosemite seed 10.1, Xcode 6.1
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!