File tree Expand file tree Collapse file tree 4 files changed +21
-18
lines changed Expand file tree Collapse file tree 4 files changed +21
-18
lines changed Original file line number Diff line number Diff line change @@ -1937,8 +1937,10 @@ Type AbstractClosureExpr::getResultType(
19371937}
19381938
19391939llvm::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
19441946bool AbstractClosureExpr::isBodyThrowing () const {
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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) {
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments