@@ -1087,7 +1087,8 @@ static DirectlyReferencedTypeDecls
1087
1087
directReferencesForTypeRepr (Evaluator &evaluator, ASTContext &ctx,
1088
1088
TypeRepr *typeRepr, DeclContext *dc,
1089
1089
bool allowUsableFromInline,
1090
- bool rhsOfSelfRequirement);
1090
+ bool rhsOfSelfRequirement,
1091
+ bool allowProtocolMembers);
1091
1092
1092
1093
// / Retrieve the set of type declarations that are directly referenced from
1093
1094
// / the given type.
@@ -1148,7 +1149,8 @@ SelfBounds SelfBoundsFromWhereClauseRequest::evaluate(
1148
1149
rhsDecls = directReferencesForTypeRepr (evaluator, ctx, typeRepr,
1149
1150
const_cast <DeclContext *>(dc),
1150
1151
/* allowUsableFromInline=*/ false ,
1151
- /* rhsOfSelfRequirement=*/ true );
1152
+ /* rhsOfSelfRequirement=*/ true ,
1153
+ /* allowProtocolMembers=*/ true );
1152
1154
}
1153
1155
1154
1156
SmallVector<ModuleDecl *, 2 > modulesFound;
@@ -1212,7 +1214,8 @@ TypeDeclsFromWhereClauseRequest::evaluate(Evaluator &evaluator,
1212
1214
auto resolve = [&](TypeRepr *typeRepr) {
1213
1215
auto decls = directReferencesForTypeRepr (evaluator, ctx, typeRepr, ext,
1214
1216
/* allowUsableFromInline=*/ false ,
1215
- /* rhsOfSelfRequirement=*/ false );
1217
+ /* rhsOfSelfRequirement=*/ false ,
1218
+ /* allowProtocolMembers=*/ true );
1216
1219
result.first .insert (result.first .end (),
1217
1220
decls.first .begin (),
1218
1221
decls.first .end ());
@@ -2843,10 +2846,11 @@ directReferencesForUnqualifiedTypeLookup(DeclNameRef name,
2843
2846
SourceLoc loc, DeclContext *dc,
2844
2847
LookupOuterResults lookupOuter,
2845
2848
bool allowUsableFromInline,
2846
- bool rhsOfSelfRequirement) {
2847
- UnqualifiedLookupOptions options =
2848
- UnqualifiedLookupFlags::TypeLookup |
2849
- UnqualifiedLookupFlags::AllowProtocolMembers;
2849
+ bool rhsOfSelfRequirement,
2850
+ bool allowProtocolMembers) {
2851
+ UnqualifiedLookupOptions options = UnqualifiedLookupFlags::TypeLookup;
2852
+ if (allowProtocolMembers)
2853
+ options |= UnqualifiedLookupFlags::AllowProtocolMembers;
2850
2854
if (lookupOuter == LookupOuterResults::Included)
2851
2855
options |= UnqualifiedLookupFlags::IncludeOuterResults;
2852
2856
@@ -2960,11 +2964,12 @@ static DirectlyReferencedTypeDecls
2960
2964
directReferencesForDeclRefTypeRepr (Evaluator &evaluator, ASTContext &ctx,
2961
2965
DeclRefTypeRepr *repr, DeclContext *dc,
2962
2966
bool allowUsableFromInline,
2963
- bool rhsOfSelfRequirement) {
2967
+ bool rhsOfSelfRequirement,
2968
+ bool allowProtocolMembers) {
2964
2969
if (auto *qualIdentTR = dyn_cast<QualifiedIdentTypeRepr>(repr)) {
2965
2970
auto result = directReferencesForTypeRepr (
2966
2971
evaluator, ctx, qualIdentTR->getBase (), dc,
2967
- allowUsableFromInline, rhsOfSelfRequirement);
2972
+ allowUsableFromInline, rhsOfSelfRequirement, allowProtocolMembers );
2968
2973
2969
2974
// For a qualified identifier, perform qualified name lookup.
2970
2975
result.first = directReferencesForQualifiedTypeLookup (
@@ -2977,14 +2982,15 @@ directReferencesForDeclRefTypeRepr(Evaluator &evaluator, ASTContext &ctx,
2977
2982
// For an unqualified identifier, perform unqualified name lookup.
2978
2983
return directReferencesForUnqualifiedTypeLookup (
2979
2984
repr->getNameRef (), repr->getLoc (), dc, LookupOuterResults::Excluded,
2980
- allowUsableFromInline, rhsOfSelfRequirement);
2985
+ allowUsableFromInline, rhsOfSelfRequirement, allowProtocolMembers );
2981
2986
}
2982
2987
2983
2988
static DirectlyReferencedTypeDecls
2984
2989
directReferencesForTypeRepr (Evaluator &evaluator,
2985
2990
ASTContext &ctx, TypeRepr *typeRepr,
2986
2991
DeclContext *dc, bool allowUsableFromInline,
2987
- bool rhsOfSelfRequirement) {
2992
+ bool rhsOfSelfRequirement,
2993
+ bool allowProtocolMembers) {
2988
2994
DirectlyReferencedTypeDecls result;
2989
2995
2990
2996
switch (typeRepr->getKind ()) {
@@ -2997,7 +3003,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
2997
3003
return directReferencesForTypeRepr (evaluator, ctx,
2998
3004
attributed->getTypeRepr (), dc,
2999
3005
allowUsableFromInline,
3000
- rhsOfSelfRequirement);
3006
+ rhsOfSelfRequirement,
3007
+ allowProtocolMembers);
3001
3008
}
3002
3009
3003
3010
case TypeReprKind::Composition: {
@@ -3006,7 +3013,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3006
3013
auto componentResult =
3007
3014
directReferencesForTypeRepr (evaluator, ctx, component, dc,
3008
3015
allowUsableFromInline,
3009
- rhsOfSelfRequirement);
3016
+ rhsOfSelfRequirement,
3017
+ allowProtocolMembers);
3010
3018
result.first .insert (result.first .end (),
3011
3019
componentResult.first .begin (),
3012
3020
componentResult.first .end ());
@@ -3022,7 +3030,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3022
3030
return directReferencesForDeclRefTypeRepr (evaluator, ctx,
3023
3031
cast<DeclRefTypeRepr>(typeRepr),
3024
3032
dc, allowUsableFromInline,
3025
- rhsOfSelfRequirement);
3033
+ rhsOfSelfRequirement,
3034
+ allowProtocolMembers);
3026
3035
3027
3036
case TypeReprKind::Dictionary:
3028
3037
result.first .push_back (ctx.getDictionaryDecl ());
@@ -3034,7 +3043,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3034
3043
result = directReferencesForTypeRepr (evaluator, ctx,
3035
3044
tupleRepr->getElementType (0 ), dc,
3036
3045
allowUsableFromInline,
3037
- rhsOfSelfRequirement);
3046
+ rhsOfSelfRequirement,
3047
+ allowProtocolMembers);
3038
3048
} else {
3039
3049
result.first .push_back (ctx.getBuiltinTupleDecl ());
3040
3050
}
@@ -3046,23 +3056,26 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3046
3056
return directReferencesForTypeRepr (evaluator, ctx,
3047
3057
packExpansionRepr->getElementType (), dc,
3048
3058
allowUsableFromInline,
3049
- rhsOfSelfRequirement);
3059
+ rhsOfSelfRequirement,
3060
+ allowProtocolMembers);
3050
3061
}
3051
3062
3052
3063
case TypeReprKind::PackExpansion: {
3053
3064
auto packExpansionRepr = cast<PackExpansionTypeRepr>(typeRepr);
3054
3065
return directReferencesForTypeRepr (evaluator, ctx,
3055
3066
packExpansionRepr->getPatternType (), dc,
3056
3067
allowUsableFromInline,
3057
- rhsOfSelfRequirement);
3068
+ rhsOfSelfRequirement,
3069
+ allowProtocolMembers);
3058
3070
}
3059
3071
3060
3072
case TypeReprKind::PackElement: {
3061
3073
auto packReferenceRepr = cast<PackElementTypeRepr>(typeRepr);
3062
3074
return directReferencesForTypeRepr (evaluator, ctx,
3063
3075
packReferenceRepr->getPackType (), dc,
3064
3076
allowUsableFromInline,
3065
- rhsOfSelfRequirement);
3077
+ rhsOfSelfRequirement,
3078
+ allowProtocolMembers);
3066
3079
}
3067
3080
3068
3081
case TypeReprKind::Inverse: {
@@ -3072,7 +3085,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3072
3085
auto innerResult = directReferencesForTypeRepr (evaluator, ctx,
3073
3086
inverseRepr->getConstraint (), dc,
3074
3087
allowUsableFromInline,
3075
- rhsOfSelfRequirement);
3088
+ rhsOfSelfRequirement,
3089
+ allowProtocolMembers);
3076
3090
if (innerResult.first .size () == 1 ) {
3077
3091
if (auto *proto = dyn_cast<ProtocolDecl>(innerResult.first [0 ])) {
3078
3092
if (auto ip = proto->getInvertibleProtocolKind ()) {
@@ -3182,10 +3196,16 @@ DirectlyReferencedTypeDecls InheritedDeclsReferencedRequest::evaluate(
3182
3196
else
3183
3197
dc = (DeclContext *)decl.get <const ExtensionDecl *>();
3184
3198
3199
+ // If looking at a protocol's inheritance list,
3200
+ // do not look at protocol members to avoid circularity.
3201
+ // Protocols cannot inherit from any protocol members anyway.
3202
+ bool allowProtocolMembers = (dc->getSelfProtocolDecl () == nullptr );
3203
+
3185
3204
return directReferencesForTypeRepr (evaluator, dc->getASTContext (), typeRepr,
3186
3205
const_cast <DeclContext *>(dc),
3187
3206
/* allowUsableFromInline=*/ false ,
3188
- /* rhsOfSelfRequirement=*/ false );
3207
+ /* rhsOfSelfRequirement=*/ false ,
3208
+ allowProtocolMembers);
3189
3209
}
3190
3210
3191
3211
// Fall back to semantic types.
@@ -3206,7 +3226,8 @@ DirectlyReferencedTypeDecls UnderlyingTypeDeclsReferencedRequest::evaluate(
3206
3226
return directReferencesForTypeRepr (evaluator, typealias->getASTContext (),
3207
3227
typeRepr, typealias,
3208
3228
/* allowUsableFromInline=*/ false ,
3209
- /* rhsOfSelfRequirement=*/ false );
3229
+ /* rhsOfSelfRequirement=*/ false ,
3230
+ /* allowProtocolMembers=*/ true );
3210
3231
}
3211
3232
3212
3233
// Fall back to semantic types.
@@ -3373,7 +3394,8 @@ ExtendedNominalRequest::evaluate(Evaluator &evaluator,
3373
3394
DirectlyReferencedTypeDecls referenced =
3374
3395
directReferencesForTypeRepr (evaluator, ctx, typeRepr, ext->getParent (),
3375
3396
ext->isInSpecializeExtensionContext (),
3376
- /* rhsOfSelfRequirement=*/ false );
3397
+ /* rhsOfSelfRequirement=*/ false ,
3398
+ /* allowProtocolMembers=*/ true );
3377
3399
3378
3400
// Resolve those type declarations to nominal type declarations.
3379
3401
SmallVector<ModuleDecl *, 2 > modulesFound;
@@ -3423,7 +3445,8 @@ bool TypeRepr::isProtocolOrProtocolComposition(DeclContext *dc) {
3423
3445
auto &ctx = dc->getASTContext ();
3424
3446
auto references = directReferencesForTypeRepr (ctx.evaluator , ctx, this , dc,
3425
3447
/* allowUsableFromInline=*/ false ,
3426
- /* rhsOfSelfRequirement=*/ false );
3448
+ /* rhsOfSelfRequirement=*/ false ,
3449
+ /* allowProtocolMembers=*/ true );
3427
3450
return declsAreProtocols (references.first );
3428
3451
}
3429
3452
@@ -3458,7 +3481,8 @@ createTupleExtensionGenericParams(ASTContext &ctx,
3458
3481
extendedTypeRepr,
3459
3482
ext->getParent (),
3460
3483
/* allowUsableFromInline=*/ false ,
3461
- /* rhsOfSelfRequirement=*/ false );
3484
+ /* rhsOfSelfRequirement=*/ false ,
3485
+ /* allowProtocolMembers=*/ true );
3462
3486
assert (referenced.second .empty () && " Implement me" );
3463
3487
if (referenced.first .size () != 1 || !isa<TypeAliasDecl>(referenced.first [0 ]))
3464
3488
return nullptr ;
@@ -3733,7 +3757,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
3733
3757
decls = directReferencesForTypeRepr (
3734
3758
evaluator, ctx, typeRepr, dc,
3735
3759
/* allowUsableFromInline=*/ false ,
3736
- /* rhsOfSelfRequirement=*/ false );
3760
+ /* rhsOfSelfRequirement=*/ false ,
3761
+ /* allowProtocolMembers=*/ true );
3737
3762
} else if (Type type = attr->getType ()) {
3738
3763
decls = directReferencesForType (type);
3739
3764
}
@@ -3764,7 +3789,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
3764
3789
decls = directReferencesForUnqualifiedTypeLookup (
3765
3790
name, loc, dc, LookupOuterResults::Included,
3766
3791
/* allowUsableFromInline=*/ false ,
3767
- /* rhsOfSelfRequirement=*/ false );
3792
+ /* rhsOfSelfRequirement=*/ false ,
3793
+ /* allowProtocolMembers*/ true );
3768
3794
nominals = resolveTypeDeclsToNominal (evaluator, ctx, decls.first ,
3769
3795
ResolveToNominalOptions (),
3770
3796
modulesFound, anyObject);
@@ -4002,7 +4028,8 @@ ProtocolDecl *ImplementsAttrProtocolRequest::evaluate(
4002
4028
DirectlyReferencedTypeDecls referenced =
4003
4029
directReferencesForTypeRepr (evaluator, ctx, typeRepr, dc,
4004
4030
/* allowUsableFromInline=*/ false ,
4005
- /* rhsOfSelfRequirement=*/ false );
4031
+ /* rhsOfSelfRequirement=*/ false ,
4032
+ /* allowProtocolMembers=*/ true );
4006
4033
4007
4034
// Resolve those type declarations to nominal type declarations.
4008
4035
SmallVector<ModuleDecl *, 2 > modulesFound;
0 commit comments