@@ -983,10 +983,7 @@ Type AbstractFunctionDecl::getThrownInterfaceType() const {
983983 return ThrownType.getType ();
984984
985985 auto mutableThis = const_cast <AbstractFunctionDecl *>(this );
986- return evaluateOrDefault (
987- getASTContext ().evaluator ,
988- ExplicitCaughtTypeRequest{mutableThis, mutableThis},
989- Type ());
986+ return CatchNode (mutableThis).getExplicitCaughtType (getASTContext ());
990987}
991988
992989llvm::Optional<Type>
@@ -11710,7 +11707,7 @@ MacroDiscriminatorContext::getParentOf(FreestandingMacroExpansion *expansion) {
1171011707}
1171111708
1171211709llvm::Optional<Type>
11713- CatchNode::getThrownErrorTypeInContext (DeclContext *dc ) const {
11710+ CatchNode::getThrownErrorTypeInContext (ASTContext &ctx ) const {
1171411711 if (auto func = dyn_cast<AbstractFunctionDecl *>()) {
1171511712 if (auto thrownError = func->getEffectiveThrownErrorType ())
1171611713 return func->mapTypeIntoContext (*thrownError);
@@ -11733,15 +11730,15 @@ CatchNode::getThrownErrorTypeInContext(DeclContext *dc) const {
1173311730 }
1173411731
1173511732 if (auto doCatch = dyn_cast<DoCatchStmt *>()) {
11736- if (auto thrownError = doCatch->getCaughtErrorType (dc )) {
11733+ if (auto thrownError = doCatch->getCaughtErrorType ()) {
1173711734 if (thrownError->isNever ())
1173811735 return llvm::None;
1173911736
1174011737 return thrownError;
1174111738 }
1174211739
1174311740 // If we haven't computed the error type yet, return 'any Error'.
11744- return dc-> getASTContext () .getErrorExistentialType ();
11741+ return ctx .getErrorExistentialType ();
1174511742 }
1174611743
1174711744 auto tryExpr = get<AnyTryExpr *>();
@@ -11750,24 +11747,41 @@ CatchNode::getThrownErrorTypeInContext(DeclContext *dc) const {
1175011747 return thrownError;
1175111748
1175211749 // If we haven't computed the error type yet, return 'any Error'.
11753- return dc-> getASTContext () .getErrorExistentialType ();
11750+ return ctx .getErrorExistentialType ();
1175411751 }
1175511752
1175611753 if (auto optTry = llvm::dyn_cast<OptionalTryExpr>(tryExpr)) {
1175711754 if (auto thrownError = optTry->getThrownError ())
1175811755 return thrownError;
1175911756
1176011757 // If we haven't computed the error type yet, return 'any Error'.
11761- return dc-> getASTContext () .getErrorExistentialType ();
11758+ return ctx .getErrorExistentialType ();
1176211759 }
1176311760
1176411761 llvm_unreachable (" Unhandled catch node kind" );
1176511762}
1176611763
11764+ Type CatchNode::getExplicitCaughtType (ASTContext &ctx) const {
11765+ return evaluateOrDefault (
11766+ ctx.evaluator , ExplicitCaughtTypeRequest{&ctx, *this }, Type ());
11767+ }
11768+
1176711769void swift::simple_display (llvm::raw_ostream &out, CatchNode catchNode) {
1176811770 out << " catch node" ;
1176911771}
1177011772
11773+ SourceLoc swift::extractNearestSourceLoc (CatchNode catchNode) {
11774+ if (auto func = catchNode.dyn_cast <AbstractFunctionDecl *>())
11775+ return func->getLoc ();
11776+ if (auto closure = catchNode.dyn_cast <ClosureExpr *>())
11777+ return closure->getLoc ();
11778+ if (auto doCatch = catchNode.dyn_cast <DoCatchStmt *>())
11779+ return doCatch->getDoLoc ();
11780+ if (auto tryExpr = catchNode.dyn_cast <AnyTryExpr *>())
11781+ return tryExpr->getTryLoc ();
11782+ llvm_unreachable (" Unhandled catch node" );
11783+ }
11784+
1177111785// ----------------------------------------------------------------------------//
1177211786// ExplicitCaughtTypeRequest computation.
1177311787// ----------------------------------------------------------------------------//
0 commit comments