@@ -809,6 +809,24 @@ bool swift::isRepresentableInLanguage(
809
809
return false ;
810
810
}
811
811
}
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
+ };
812
830
813
831
if (AFD->hasAsync ()) {
814
832
// Asynchronous functions move all of the result value and thrown error
@@ -888,6 +906,8 @@ bool swift::isRepresentableInLanguage(
888
906
// a thrown error.
889
907
std::optional<unsigned > completionHandlerErrorParamIndex;
890
908
if (FD->hasThrows ()) {
909
+ if (isTypedThrow ())
910
+ return false ;
891
911
completionHandlerErrorParamIndex = completionHandlerParams.size ();
892
912
auto errorType = ctx.getErrorExistentialType ();
893
913
addCompletionHandlerParam (OptionalType::get (errorType));
@@ -912,6 +932,9 @@ bool swift::isRepresentableInLanguage(
912
932
SourceLoc throwsLoc;
913
933
Type resultType;
914
934
935
+ if (isTypedThrow ())
936
+ return false ;
937
+
915
938
const ConstructorDecl *ctor = nullptr ;
916
939
if (auto func = dyn_cast<FuncDecl>(AFD)) {
917
940
resultType = func->getResultInterfaceType ();
0 commit comments