Skip to content

Commit 010a412

Browse files
committed
Fix minor regressions from refactoring of caught error types
1 parent 3369e33 commit 010a412

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

lib/AST/Expr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,8 +1937,10 @@ Type AbstractClosureExpr::getResultType(
19371937
}
19381938

19391939
llvm::Optional<Type> AbstractClosureExpr::getEffectiveThrownType() const {
1940-
return getType()->castTo<AnyFunctionType>()
1941-
->getEffectiveThrownErrorType();
1940+
if (auto fnType = getType()->getAs<AnyFunctionType>())
1941+
return fnType->getEffectiveThrownErrorType();
1942+
1943+
return llvm::None;
19421944
}
19431945

19441946
bool AbstractClosureExpr::isBodyThrowing() const {

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,8 +2459,10 @@ namespace {
24592459
// Determine the thrown error type, when appropriate.
24602460
Type thrownErrorTy = [&] {
24612461
// Explicitly-specified thrown type.
2462-
if (Type explicitType = closure->getExplicitThrownType())
2463-
return explicitType;
2462+
if (closure->getExplicitThrownTypeRepr()) {
2463+
if (Type explicitType = closure->getExplicitThrownType())
2464+
return explicitType;
2465+
}
24642466

24652467
// Thrown type inferred from context.
24662468
if (auto contextualType = CS.getContextualType(

lib/Sema/CSSyntacticElement.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,16 @@ class SyntacticElementConstraintGenerator
925925
dc->getParentModule(), throwStmt->getThrowLoc());
926926
Type errorType;
927927
if (catchNode) {
928-
errorType = catchNode.getThrownErrorTypeInContext(dc).value_or(Type());
928+
// FIXME: Introduce something like getThrownErrorTypeInContext() for the
929+
// constraint solver.
930+
if (auto abstractClosure = catchNode.dyn_cast<AbstractClosureExpr *>()) {
931+
if (auto closure = dyn_cast<ClosureExpr>(abstractClosure)) {
932+
errorType = cs.getClosureType(closure)->getThrownError();
933+
}
934+
}
935+
936+
if (!errorType)
937+
errorType = catchNode.getThrownErrorTypeInContext(dc).value_or(Type());
929938
}
930939

931940
if (!errorType) {

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5680,7 +5680,7 @@ Type ExplicitCaughtTypeRequest::evaluate(
56805680
return ctx.getNeverType();
56815681
}
56825682

5683-
// We have an explici thrown error type, so resolve it.
5683+
// We have an explicit thrown error type, so resolve it.
56845684
if (!ctx.LangOpts.hasFeature(Feature::TypedThrows)) {
56855685
ctx.Diags.diagnose(thrownTypeRepr->getLoc(), diag::experimental_typed_throws);
56865686
}
@@ -5719,20 +5719,10 @@ Type ExplicitCaughtTypeRequest::evaluate(
57195719
if (closure->getThrowsLoc().isValid()) {
57205720
return ctx.getErrorExistentialType();
57215721
}
5722-
5723-
// If there is no potential throw site (based on syntactic analysis),
5724-
// then this closure is non-throwing.
5725-
auto effects = evaluateOrDefault(
5726-
evaluator, ClosureEffectsRequest{closure}, FunctionType::ExtInfo());
5727-
if (!effects.isThrowing())
5728-
return ctx.getNeverType();
57295722
}
57305723

5731-
// TODO: A throwing closure with no explicit 'throws' annotation will infer
5732-
// the thrown error type in Swift 6 and under FullTypedThrows.
5733-
5734-
// Otherwise, we throw 'any Error'.
5735-
return ctx.getErrorExistentialType();
5724+
// Thrown error type will be inferred.
5725+
return Type();
57365726
}
57375727

57385728
// do..catch statements.

0 commit comments

Comments
 (0)