[Swift] try in autoclosure makes outer closure be 'throws'
| Originator: | maxtram95 | ||
| Number: | rdar://22437049 | Date Originated: | 26-Aug-2015 05:14 PM |
| Status: | Duplicate of 22394263 (Open) | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7.0b6 (7A192o) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
Consider the following code:
func noexcept<T>(@autoclosure call: () throws -> T) -> T? {
do {
return try call()
} catch {
return nil
}
}
enum Error: ErrorType {
case SomeError
}
func throwException() throws -> Int {
throw Error.SomeError
}
func acceptClosure(closure: () -> Void) {
closure()
}
func test() {
acceptClosure {
let _ = noexcept(try throwException())
}
}
test()
It fails to compile. Error shown is "Invalid conversion from throwing function of type '() throws -> Void' to non-throwing function type '() -> Void'". It's on the line where 'acceptClosure' is called. For some reason compiler thinks that the closure that is passed to 'acceptClosure' throws, but it really can't throw since it only calls non-throwing function 'noexcept'.
If I remove @autoclosure from definition of 'noexcept' and replace 'noexcept(try throwException())' with 'noexcept { try throwException() }', it compiles fine. So autoclosure variant of the function should also compile fine.
Steps to Reproduce:
1. Install Xcode 7.0b6 (7A192o).
2. Create a playground for iOS, paste my code snippet in playground.
3. Code fails to compile with described message.
Expected Results:
Code should compile fine.
Actual Results:
Code fails to compile.
Version:
Xcode 7.0b6 (7A192o), OS X 10.10.5.
Notes:
Configuration:
Swift 2.0, Xcode 7.0b6 (7A192o), OS X 10.10.5, building for iOS 9.0.
Attachments:
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!