New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-487] Compiler fails to consider @autoclosure when satisfying try requirements #43104
Comments
This occurs whenever a func foo(_ expr: @autoclosure () throws -> Void) {
do {
try expr()
} catch {
print("error: \(error)")
}
}
func err() throws -> Void {
struct Foo: ErrorProtocol {}
throw Foo()
}
func topLevel() {
// works
foo(try err())
// warning about unreachable catch block
let _: () -> Void = {
do {
foo(try err())
} catch {}
}
// error
let _: () -> Void = {
foo(try err())
}
} |
Comment by Vaddadi Kartick (JIRA) This seems to happen even without autoclosure:
This says that the call can throw, but it is not marked with try and the error isn't handled. This is with Swift 3 on Xcode 8.2.1 (8C1002) as of Feb 2017. |
kart (JIRA User) The error is correct in your case. The correct code is ignoreException { try device.lockForConfiguration() } |
Comment by Vaddadi Kartick (JIRA) Thanks for pointing that out, and excuse my poor understanding of Swift. |
Comment by Kevin Nattinger (JIRA) This still occurs as of Xcode 9 (released) and Xcode 9.1 beta 2. |
Comment by Andrej (JIRA) This seems to be the case when using `XCTAssertNoThrow` in the context on non-throwing closure in my case. Still an issue on Xcode 9.2. |
Comment by Gereon Steffens (JIRA) Still an issue with Swift 4.2 / Xcode 10.1 when using `XCTAssertNoThrow` or `XCTAssertThrowsError` in a closure. |
Comment by Thijs de Vries (JIRA) Still an issue in swift 5.2 / XCode 11.4 Makes it hard to use quick since every it statement is a closure. |
Comment by Texot (JIRA) Still an issue in Swift 5.5.2 / XCode 13.2.1 |
Environment
Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)
Apple Swift version 3.0-dev (LLVM dffa09ffd8, Clang 9f0d189820, Swift 1c720b8) (May 9, 2016 snapshot)
Additional Detail from JIRA
md5: 144912dacff217d48a6b1ce1fd642c20
is duplicated by:
throws
declaration wiredlyIssue Description:
Minimal example shown below. In certain situations the compiler is attempting to promote the outer closure to `throws` when the `try` is automatically promoted to a closure. In other situations it correctly surmises that the auto closure makes any attempt to `catch` pointless.
The text was updated successfully, but these errors were encountered: