mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Prior to the introduction of typed throws, a `do..catch` always had a caught
error type of `any Error`, even if there were no throwing sites within
the `do` body. With typed throws, such a `do..catch` would have a
caught error type of `Never`, because it never throws. Unfortunately,
this causes code like the following to produce an error, because
`Never` cannot be pattern-matched to `HomeworkError.forgot`:
func test() {
do {
try nonthrowing()
} catch HomeworkError.forgot {
} catch {
}
}
For source-compatibility reasons, adjust the caught error type to
`any Error` in this case, so we continue to accept the code above.
Don't do this adjustment under `FullTypedThrows`, because it's only
there for compatibility.
Fixes rdar://121526201.
6.5 KiB
6.5 KiB