@@ -855,26 +855,6 @@ class Context {
855
855
};
856
856
857
857
private:
858
- static Kind getKindForFunctionBody (Type type, unsigned numArgs) {
859
- // / Determine whether calling a function of the specified type with the
860
- // / specified number of arguments would throw.
861
- if (!type) return Kind::Handled;
862
-
863
- assert (numArgs > 0 );
864
- while (true ) {
865
- auto fnType = type->getAs <AnyFunctionType>();
866
- if (!fnType) return Kind::Handled;
867
-
868
- if (fnType->getExtInfo ().isThrowing ())
869
- return Kind::Handled;
870
-
871
- if (--numArgs == 0 )
872
- return Kind::NonThrowingFunction;
873
-
874
- type = fnType->getResult ();
875
- }
876
- }
877
-
878
858
static Context getContextForPatternBinding (PatternBindingDecl *pbd) {
879
859
if (!pbd->isStatic () && pbd->getDeclContext ()->isTypeContext ()) {
880
860
return Context (Kind::IVarInitializer);
@@ -924,8 +904,7 @@ class Context {
924
904
}
925
905
}
926
906
927
- return Context (getKindForFunctionBody (
928
- D->getInterfaceType (), D->getNumCurryLevels ()));
907
+ return Context (D->hasThrows () ? Kind::Handled : Kind::NonThrowingFunction);
929
908
}
930
909
931
910
static Context forDeferBody () {
@@ -948,10 +927,16 @@ class Context {
948
927
}
949
928
950
929
static Context forClosure (AbstractClosureExpr *E) {
951
- auto kind = getKindForFunctionBody (E->getType (), 1 );
952
- if (kind != Kind::Handled && isa<AutoClosureExpr>(E))
953
- kind = Kind::NonThrowingAutoClosure;
954
- return Context (kind);
930
+ // Determine whether the closure has throwing function type.
931
+ bool closureTypeThrows = true ;
932
+ if (auto closureType = E->getType ()) {
933
+ if (auto fnType = closureType->getAs <AnyFunctionType>())
934
+ closureTypeThrows = fnType->isThrowing ();
935
+ }
936
+
937
+ return Context (closureTypeThrows ? Kind::Handled
938
+ : isa<AutoClosureExpr>(E) ? Kind::NonThrowingAutoClosure
939
+ : Kind::NonThrowingFunction);
955
940
}
956
941
957
942
static Context forCatchPattern (CaseStmt *S) {
0 commit comments