Open JessyCatterwaul opened 4 months ago
This looks like it's possibly a duplicate of #75430
I worked through that one again, and, as I'm about to comment there, you are correct. One of these issues can be closed, but the other one has to have a name with "autoclosure" in it.
This seems related, but doesn't require auto-closure.
struct SomeError: Error {}
struct CustomError: Error {}
let typedThrowingClosure: () throws(CustomError) -> Bool = {
do { throw SomeError() } catch { throw CustomError() }
}
I think throws from inside the catch just get defaulted to "any Error", can't figure out any way to "Hint" the catch throwing type.
This seems related, but doesn't require auto-closure.
As I said in a comment in #75430, that is not the same issue, and mention of it should be removed from here and made into another issues if it hasn't been already. (I never logged that bug, but it's been the behavior since day 1 of Xcode 16.)
You just have to explicitly type the error within the closure:
var typedThrowingClosure: () throws(CustomError) -> Bool
typedThrowingClosure = { () throws(CustomError) in
do { throw SomeError() } catch { throw .init() }
}
typedThrowingClosure = { () throws(_) in
do { throw SomeError() } catch { throw CustomError() }
}
Description
The type information is there. It just needs some help to be brought to the surface.
Reproduction
Given these…
…all but the last line compiles.
Expected behavior
The types from autoclosures' errors project outwards so they can be used implicitly, as happens with not-auto-closures.
Environment
swift-driver version: 1.112.3 Apple Swift version 6.0 (swiftlang-6.0.0.6.8 clang-1600.0.23.1) Target: arm64-apple-macosx14.0
Additional information
I want this to work!