@@ -809,6 +809,24 @@ bool swift::isRepresentableInLanguage(
809809 return false ;
810810 }
811811 }
812+ auto isTypedThrow = [&]() {
813+ // With no AST token this should be `throws`
814+ if (!AFD->getThrownTypeRepr ())
815+ return false ;
816+ // Or it is a `throws(<ErrorType>)`
817+ CanType thrownType = AFD->getThrownInterfaceType ()->getCanonicalType ();
818+ // TODO: only `throws(Error)` is allowed.
819+ // Throwing `any MyError` that confronts `Error` is not implemented yet.
820+ // Shall we allow `any MyError` in the future, we should check against
821+ // `isExistentialType` instead.
822+ if (thrownType->isErrorExistentialType ())
823+ return false ;
824+ softenIfAccessNote (AFD, Reason.getAttr (),
825+ AFD->diagnose (diag::typed_thrown_in_objc_forbidden)
826+ .limitBehavior (behavior));
827+ Reason.describe (AFD);
828+ return true ;
829+ };
812830
813831 if (AFD->hasAsync ()) {
814832 // Asynchronous functions move all of the result value and thrown error
@@ -888,6 +906,8 @@ bool swift::isRepresentableInLanguage(
888906 // a thrown error.
889907 std::optional<unsigned > completionHandlerErrorParamIndex;
890908 if (FD->hasThrows ()) {
909+ if (isTypedThrow ())
910+ return false ;
891911 completionHandlerErrorParamIndex = completionHandlerParams.size ();
892912 auto errorType = ctx.getErrorExistentialType ();
893913 addCompletionHandlerParam (OptionalType::get (errorType));
@@ -912,6 +932,9 @@ bool swift::isRepresentableInLanguage(
912932 SourceLoc throwsLoc;
913933 Type resultType;
914934
935+ if (isTypedThrow ())
936+ return false ;
937+
915938 const ConstructorDecl *ctor = nullptr ;
916939 if (auto func = dyn_cast<FuncDecl>(AFD)) {
917940 resultType = func->getResultInterfaceType ();
0 commit comments