-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
Typed throws seems to presume a do/catch block rethrowing the error it caught, is always throwing any Error
, when in fact it may know the type of the thrown error.
Reproduction
func doStuff<E: Error>(
with closure: () throws(E) -> Void
) throws(E) -> Void {
do {
do {
try closure()
} catch {
throw error
}
} catch {
throw error // error: thrown expression type 'any Error' cannot be converted to error type 'E'
}
}
(Same behavior with FullTypedThrows enabled)
Expected behavior
This should compile — the inner do
block can only throw E
, and therefore the outer catch
block can only throw E
Environment
swift-driver version: 1.111.2 Apple Swift version 6.0 (swiftlang-6.0.0.5.15 clang-1600.0.22.6)
Target: arm64-apple-macosx14.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels