@@ -2924,7 +2924,7 @@ static bool declsAreAssociatedTypes(ArrayRef<TypeDecl *> decls) {
29242924// / Verify there is at least one protocols in the set of declarations.
29252925static bool declsAreProtocols (ArrayRef<TypeDecl *> decls) {
29262926 if (decls.empty ())
2927- return false ;
2927+ return false ; // Below, check outer type repr is a protocol, if not bail early
29282928 return llvm::any_of (decls, [&](const TypeDecl *decl) {
29292929 if (auto *alias = dyn_cast<TypeAliasDecl>(decl)) {
29302930 auto ty = alias->getUnderlyingType ();
@@ -2933,14 +2933,12 @@ static bool declsAreProtocols(ArrayRef<TypeDecl *> decls) {
29332933 return false ;
29342934 }
29352935 return isa<ProtocolDecl>(decl);
2936- });;;
2936+ });
29372937}
29382938
2939- bool TypeRepr::isProtocol (DeclContext *dc){
2939+ bool TypeRepr::isProtocolOrProtocolComposition (DeclContext *dc){
29402940 auto &ctx = dc->getASTContext ();
2941- return findIf ([&ctx, dc](TypeRepr *ty) {
2942- return declsAreProtocols (directReferencesForTypeRepr (ctx.evaluator , ctx, ty, dc));
2943- });
2941+ return declsAreProtocols (directReferencesForTypeRepr (ctx.evaluator , ctx, this , dc));
29442942}
29452943
29462944static GenericParamList *
@@ -2962,7 +2960,8 @@ createExtensionGenericParams(ASTContext &ctx,
29622960 return toParams;
29632961}
29642962
2965- CollectedOpaqueReprs swift::collectOpaqueReturnTypeReprs (TypeRepr *r, ASTContext &ctx, DeclContext *d) {
2963+ CollectedOpaqueReprs swift::collectOpaqueTypeReprs (TypeRepr *r, ASTContext &ctx,
2964+ DeclContext *d) {
29662965 class Walker : public ASTWalker {
29672966 CollectedOpaqueReprs &Reprs;
29682967 ASTContext &Ctx;
@@ -2993,15 +2992,19 @@ CollectedOpaqueReprs swift::collectOpaqueReturnTypeReprs(TypeRepr *r, ASTContext
29932992
29942993 if (auto existential = dyn_cast<ExistentialTypeRepr>(repr)) {
29952994 return Action::SkipChildren ();
2996- } else if (auto compositionRepr = dyn_cast<CompositionTypeRepr>(repr)) {
2997- if (!compositionRepr ->isTypeReprAny ())
2998- Reprs.push_back (compositionRepr );
2995+ } else if (auto composition = dyn_cast<CompositionTypeRepr>(repr)) {
2996+ if (!composition ->isTypeReprAny ())
2997+ Reprs.push_back (composition );
29992998 return Action::SkipChildren ();
30002999 } else if (auto generic = dyn_cast<GenericIdentTypeRepr>(repr)) {
3000+ if (generic->isProtocolOrProtocolComposition (dc)){
3001+ Reprs.push_back (generic);
3002+ return Action::SkipChildren ();
3003+ }
30013004 return Action::Continue ();
3002- } else if (auto declRefTR = dyn_cast<DeclRefTypeRepr>(repr)) {
3003- if (declRefTR-> isProtocol (dc))
3004- Reprs.push_back (declRefTR );
3005+ } else if (auto declRef = dyn_cast<DeclRefTypeRepr>(repr)) {
3006+ if (declRef-> isProtocolOrProtocolComposition (dc))
3007+ Reprs.push_back (declRef );
30053008 }
30063009 return Action::Continue ();
30073010 }
@@ -3043,7 +3046,7 @@ createOpaqueParameterGenericParams(GenericContext *genericContext, GenericParamL
30433046
30443047 // Plain protocols should imply 'some' with experimetal feature
30453048 CollectedOpaqueReprs typeReprs;
3046- typeReprs = collectOpaqueReturnTypeReprs (typeRepr, ctx, dc);
3049+ typeReprs = collectOpaqueTypeReprs (typeRepr, ctx, dc);
30473050
30483051 for (auto repr : typeReprs) {
30493052
0 commit comments