Make sure we record "Never" as the thrown error type for try!/try?

This commit is contained in:
Doug Gregor
2023-11-03 16:24:46 -07:00
parent 844b46fae5
commit b49d8b63bc
2 changed files with 16 additions and 0 deletions

View File

@@ -3104,6 +3104,8 @@ private:
if (auto thrownError = TypeChecker::canThrow(Ctx, E->getSubExpr())) {
E->setThrownError(*thrownError);
} else {
E->setThrownError(Ctx.getNeverType());
}
scope.preserveCoverageFromOptionalOrForcedTryOperand();
@@ -3123,6 +3125,8 @@ private:
if (auto thrownError = TypeChecker::canThrow(Ctx, E->getSubExpr())) {
E->setThrownError(*thrownError);
} else {
E->setThrownError(Ctx.getNeverType());
}
scope.preserveCoverageFromOptionalOrForcedTryOperand();

View File

@@ -37,3 +37,15 @@ func throwsAnything() throws {
// CHECK: optional_try_expr{{.*}}thrown_error="MyError"
try? printOrFail("ssshhhhh")
}
func doesNotThrow() { }
func throwsNothing() {
// CHECK-LABE: func_decl{{.*}}"throwsNothing()"
// CHECK: force_try_expr{{.*}}thrown_error="Never"
try! doesNotThrow()
// CHECK: optional_try_expr{{.*}}thrown_error="Never"
try? doesNotThrow()
}