Open
Description
Description
While working with typed throws, I found that the Result.init(catching:) doesn't infer the typed error. But its signature implies that it should.
public enum Result<Success, Failure> where Failure : Error, Success : ~Copyable {
// …
public init(catching body: () throws(Failure) -> Success) {
// …
}
}
This issue might be related to other typed throws
issues like #75430 or #69985.
Reproduction
class MyService {
enum MyServiceError: Error {
case unknown
}
func attemptSomethingWithTypedError() throws(MyServiceError) {
throw .unknown
}
func wrapInResult() {
// ❗️ compilation error
// result is inferred to be of type `Result<(), any Error>` instead
let result: Result<(), MyServiceError> = Result(catching: { try attemptSomethingWithTypedError() })
}
}
Expected behavior
In this example, I expect the inferred result type to be Result<(), MyServiceError>
.
Environment
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
Additional information
Reproducible in Xcode playground + Swift REPL.