@@ -2924,7 +2924,7 @@ static bool declsAreAssociatedTypes(ArrayRef<TypeDecl *> decls) {
2924
2924
// / Verify there is at least one protocols in the set of declarations.
2925
2925
static bool declsAreProtocols (ArrayRef<TypeDecl *> decls) {
2926
2926
if (decls.empty ())
2927
- return false ;
2927
+ return false ; // Below, check outer type repr is a protocol, if not bail early
2928
2928
return llvm::any_of (decls, [&](const TypeDecl *decl) {
2929
2929
if (auto *alias = dyn_cast<TypeAliasDecl>(decl)) {
2930
2930
auto ty = alias->getUnderlyingType ();
@@ -2933,14 +2933,12 @@ static bool declsAreProtocols(ArrayRef<TypeDecl *> decls) {
2933
2933
return false ;
2934
2934
}
2935
2935
return isa<ProtocolDecl>(decl);
2936
- });;;
2936
+ });
2937
2937
}
2938
2938
2939
- bool TypeRepr::isProtocol (DeclContext *dc){
2939
+ bool TypeRepr::isProtocolOrProtocolComposition (DeclContext *dc){
2940
2940
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));
2944
2942
}
2945
2943
2946
2944
static GenericParamList *
@@ -2993,15 +2991,19 @@ CollectedOpaqueReprs swift::collectOpaqueReturnTypeReprs(TypeRepr *r, ASTContext
2993
2991
2994
2992
if (auto existential = dyn_cast<ExistentialTypeRepr>(repr)) {
2995
2993
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 );
2999
2997
return Action::SkipChildren ();
3000
2998
} else if (auto generic = dyn_cast<GenericIdentTypeRepr>(repr)) {
2999
+ if (generic->isProtocolOrProtocolComposition (dc)){
3000
+ Reprs.push_back (generic);
3001
+ return Action::SkipChildren ();
3002
+ }
3001
3003
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 );
3005
3007
}
3006
3008
return Action::Continue ();
3007
3009
}
0 commit comments