@@ -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 *
@@ -2993,15 +2991,19 @@ CollectedOpaqueReprs swift::collectOpaqueReturnTypeReprs(TypeRepr *r, ASTContext
29932991
29942992 if (auto existential = dyn_cast<ExistentialTypeRepr>(repr)) {
29952993 return Action::SkipChildren ();
2996- } else if (auto compositionRepr = dyn_cast<CompositionTypeRepr>(repr)) {
2997- if (!compositionRepr ->isTypeReprAny ())
2998- Reprs.push_back (compositionRepr );
2994+ } else if (auto composition = dyn_cast<CompositionTypeRepr>(repr)) {
2995+ if (!composition ->isTypeReprAny ())
2996+ Reprs.push_back (composition );
29992997 return Action::SkipChildren ();
30002998 } else if (auto generic = dyn_cast<GenericIdentTypeRepr>(repr)) {
2999+ if (generic->isProtocolOrProtocolComposition (dc)){
3000+ Reprs.push_back (generic);
3001+ return Action::SkipChildren ();
3002+ }
30013003 return Action::Continue ();
3002- } else if (auto declRefTR = dyn_cast<DeclRefTypeRepr>(repr)) {
3003- if (declRefTR-> isProtocol (dc))
3004- Reprs.push_back (declRefTR );
3004+ } else if (auto declRef = dyn_cast<DeclRefTypeRepr>(repr)) {
3005+ if (declRef-> isProtocolOrProtocolComposition (dc))
3006+ Reprs.push_back (declRef );
30053007 }
30063008 return Action::Continue ();
30073009 }
0 commit comments