Skip to content

Commit 47a6d67

Browse files
authored
Merge pull request #69653 from DougGregor/try-question-bang-never
Make sure we record "Never" as the thrown error type for try!/try?
2 parents 18ab9f5 + b49d8b6 commit 47a6d67

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,6 +3104,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
31043104

31053105
if (auto thrownError = TypeChecker::canThrow(Ctx, E->getSubExpr())) {
31063106
E->setThrownError(*thrownError);
3107+
} else {
3108+
E->setThrownError(Ctx.getNeverType());
31073109
}
31083110

31093111
scope.preserveCoverageFromOptionalOrForcedTryOperand();
@@ -3123,6 +3125,8 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
31233125

31243126
if (auto thrownError = TypeChecker::canThrow(Ctx, E->getSubExpr())) {
31253127
E->setThrownError(*thrownError);
3128+
} else {
3129+
E->setThrownError(Ctx.getNeverType());
31263130
}
31273131

31283132
scope.preserveCoverageFromOptionalOrForcedTryOperand();

test/stmt/typed_throws_ast.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ func throwsAnything() throws {
3737
// CHECK: optional_try_expr{{.*}}thrown_error="MyError"
3838
try? printOrFail("ssshhhhh")
3939
}
40+
41+
func doesNotThrow() { }
42+
43+
func throwsNothing() {
44+
// CHECK-LABE: func_decl{{.*}}"throwsNothing()"
45+
46+
// CHECK: force_try_expr{{.*}}thrown_error="Never"
47+
try! doesNotThrow()
48+
49+
// CHECK: optional_try_expr{{.*}}thrown_error="Never"
50+
try? doesNotThrow()
51+
}

0 commit comments

Comments
 (0)