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(
1937
1937
}
1938
1938
1939
1939
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;
1942
1944
}
1943
1945
1944
1946
bool AbstractClosureExpr::isBodyThrowing () const {
Original file line number Diff line number Diff line change @@ -2459,8 +2459,10 @@ namespace {
2459
2459
// Determine the thrown error type, when appropriate.
2460
2460
Type thrownErrorTy = [&] {
2461
2461
// 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
+ }
2464
2466
2465
2467
// Thrown type inferred from context.
2466
2468
if (auto contextualType = CS.getContextualType (
Original file line number Diff line number Diff line change @@ -925,7 +925,16 @@ class SyntacticElementConstraintGenerator
925
925
dc->getParentModule (), throwStmt->getThrowLoc ());
926
926
Type errorType;
927
927
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 ());
929
938
}
930
939
931
940
if (!errorType) {
Original file line number Diff line number Diff line change @@ -5680,7 +5680,7 @@ Type ExplicitCaughtTypeRequest::evaluate(
5680
5680
return ctx.getNeverType ();
5681
5681
}
5682
5682
5683
- // We have an explici thrown error type, so resolve it.
5683
+ // We have an explicit thrown error type, so resolve it.
5684
5684
if (!ctx.LangOpts .hasFeature (Feature::TypedThrows)) {
5685
5685
ctx.Diags .diagnose (thrownTypeRepr->getLoc (), diag::experimental_typed_throws);
5686
5686
}
@@ -5719,20 +5719,10 @@ Type ExplicitCaughtTypeRequest::evaluate(
5719
5719
if (closure->getThrowsLoc ().isValid ()) {
5720
5720
return ctx.getErrorExistentialType ();
5721
5721
}
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 ();
5729
5722
}
5730
5723
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 ();
5736
5726
}
5737
5727
5738
5728
// do..catch statements.
You can’t perform that action at this time.
0 commit comments