Typed Throws in Closures
★★★- typed-throws
Swift 6.3.2 Report an issue
Verified quizzes have their expected answer checked by compiling and running the code with the listed Swift toolchain during the site build.
enum E: Error {
case bad
}
func b() throws(E) -> Int {
throw E.bad
}
func requirement(_: Result<Int, E>) {}
let r = Result { try b() }
requirement(r)
Hint
b() has typed throws (throws(E)), so its thrown errors are statically
known to be E. What does the closure in Result.init(catching:) infer for its
Failure parameter?