@@ -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 ());
@@ -2882,10 +2885,11 @@ directReferencesForUnqualifiedTypeLookup(DeclNameRef name,
2882
2885
SourceLoc loc, DeclContext *dc,
2883
2886
LookupOuterResults lookupOuter,
2884
2887
bool allowUsableFromInline,
2885
- bool rhsOfSelfRequirement) {
2886
- UnqualifiedLookupOptions options =
2887
- UnqualifiedLookupFlags::TypeLookup |
2888
- UnqualifiedLookupFlags::AllowProtocolMembers;
2888
+ bool rhsOfSelfRequirement,
2889
+ bool allowProtocolMembers) {
2890
+ UnqualifiedLookupOptions options = UnqualifiedLookupFlags::TypeLookup;
2891
+ if (allowProtocolMembers)
2892
+ options |= UnqualifiedLookupFlags::AllowProtocolMembers;
2889
2893
if (lookupOuter == LookupOuterResults::Included)
2890
2894
options |= UnqualifiedLookupFlags::IncludeOuterResults;
2891
2895
@@ -2999,11 +3003,12 @@ static DirectlyReferencedTypeDecls
2999
3003
directReferencesForDeclRefTypeRepr (Evaluator &evaluator, ASTContext &ctx,
3000
3004
DeclRefTypeRepr *repr, DeclContext *dc,
3001
3005
bool allowUsableFromInline,
3002
- bool rhsOfSelfRequirement) {
3006
+ bool rhsOfSelfRequirement,
3007
+ bool allowProtocolMembers) {
3003
3008
if (auto *qualIdentTR = dyn_cast<QualifiedIdentTypeRepr>(repr)) {
3004
3009
auto result = directReferencesForTypeRepr (
3005
3010
evaluator, ctx, qualIdentTR->getBase (), dc,
3006
- allowUsableFromInline, rhsOfSelfRequirement);
3011
+ allowUsableFromInline, rhsOfSelfRequirement, allowProtocolMembers );
3007
3012
3008
3013
// For a qualified identifier, perform qualified name lookup.
3009
3014
result.first = directReferencesForQualifiedTypeLookup (
@@ -3016,14 +3021,15 @@ directReferencesForDeclRefTypeRepr(Evaluator &evaluator, ASTContext &ctx,
3016
3021
// For an unqualified identifier, perform unqualified name lookup.
3017
3022
return directReferencesForUnqualifiedTypeLookup (
3018
3023
repr->getNameRef (), repr->getLoc (), dc, LookupOuterResults::Excluded,
3019
- allowUsableFromInline, rhsOfSelfRequirement);
3024
+ allowUsableFromInline, rhsOfSelfRequirement, allowProtocolMembers );
3020
3025
}
3021
3026
3022
3027
static DirectlyReferencedTypeDecls
3023
3028
directReferencesForTypeRepr (Evaluator &evaluator,
3024
3029
ASTContext &ctx, TypeRepr *typeRepr,
3025
3030
DeclContext *dc, bool allowUsableFromInline,
3026
- bool rhsOfSelfRequirement) {
3031
+ bool rhsOfSelfRequirement,
3032
+ bool allowProtocolMembers) {
3027
3033
DirectlyReferencedTypeDecls result;
3028
3034
3029
3035
switch (typeRepr->getKind ()) {
@@ -3036,7 +3042,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3036
3042
return directReferencesForTypeRepr (evaluator, ctx,
3037
3043
attributed->getTypeRepr (), dc,
3038
3044
allowUsableFromInline,
3039
- rhsOfSelfRequirement);
3045
+ rhsOfSelfRequirement,
3046
+ allowProtocolMembers);
3040
3047
}
3041
3048
3042
3049
case TypeReprKind::Composition: {
@@ -3045,7 +3052,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3045
3052
auto componentResult =
3046
3053
directReferencesForTypeRepr (evaluator, ctx, component, dc,
3047
3054
allowUsableFromInline,
3048
- rhsOfSelfRequirement);
3055
+ rhsOfSelfRequirement,
3056
+ allowProtocolMembers);
3049
3057
result.first .insert (result.first .end (),
3050
3058
componentResult.first .begin (),
3051
3059
componentResult.first .end ());
@@ -3061,7 +3069,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3061
3069
return directReferencesForDeclRefTypeRepr (evaluator, ctx,
3062
3070
cast<DeclRefTypeRepr>(typeRepr),
3063
3071
dc, allowUsableFromInline,
3064
- rhsOfSelfRequirement);
3072
+ rhsOfSelfRequirement,
3073
+ allowProtocolMembers);
3065
3074
3066
3075
case TypeReprKind::Dictionary:
3067
3076
result.first .push_back (ctx.getDictionaryDecl ());
@@ -3073,7 +3082,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3073
3082
result = directReferencesForTypeRepr (evaluator, ctx,
3074
3083
tupleRepr->getElementType (0 ), dc,
3075
3084
allowUsableFromInline,
3076
- rhsOfSelfRequirement);
3085
+ rhsOfSelfRequirement,
3086
+ allowProtocolMembers);
3077
3087
} else {
3078
3088
result.first .push_back (ctx.getBuiltinTupleDecl ());
3079
3089
}
@@ -3085,23 +3095,26 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3085
3095
return directReferencesForTypeRepr (evaluator, ctx,
3086
3096
packExpansionRepr->getElementType (), dc,
3087
3097
allowUsableFromInline,
3088
- rhsOfSelfRequirement);
3098
+ rhsOfSelfRequirement,
3099
+ allowProtocolMembers);
3089
3100
}
3090
3101
3091
3102
case TypeReprKind::PackExpansion: {
3092
3103
auto packExpansionRepr = cast<PackExpansionTypeRepr>(typeRepr);
3093
3104
return directReferencesForTypeRepr (evaluator, ctx,
3094
3105
packExpansionRepr->getPatternType (), dc,
3095
3106
allowUsableFromInline,
3096
- rhsOfSelfRequirement);
3107
+ rhsOfSelfRequirement,
3108
+ allowProtocolMembers);
3097
3109
}
3098
3110
3099
3111
case TypeReprKind::PackElement: {
3100
3112
auto packReferenceRepr = cast<PackElementTypeRepr>(typeRepr);
3101
3113
return directReferencesForTypeRepr (evaluator, ctx,
3102
3114
packReferenceRepr->getPackType (), dc,
3103
3115
allowUsableFromInline,
3104
- rhsOfSelfRequirement);
3116
+ rhsOfSelfRequirement,
3117
+ allowProtocolMembers);
3105
3118
}
3106
3119
3107
3120
case TypeReprKind::Inverse: {
@@ -3111,7 +3124,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
3111
3124
auto innerResult = directReferencesForTypeRepr (evaluator, ctx,
3112
3125
inverseRepr->getConstraint (), dc,
3113
3126
allowUsableFromInline,
3114
- rhsOfSelfRequirement);
3127
+ rhsOfSelfRequirement,
3128
+ allowProtocolMembers);
3115
3129
if (innerResult.first .size () == 1 ) {
3116
3130
if (auto *proto = dyn_cast<ProtocolDecl>(innerResult.first [0 ])) {
3117
3131
if (auto ip = proto->getInvertibleProtocolKind ()) {
@@ -3221,10 +3235,16 @@ DirectlyReferencedTypeDecls InheritedDeclsReferencedRequest::evaluate(
3221
3235
else
3222
3236
dc = (DeclContext *)decl.get <const ExtensionDecl *>();
3223
3237
3238
+ // If looking at a protocol's inheritance list,
3239
+ // do not look at protocol members to avoid circularity.
3240
+ // Protocols cannot inherit from any protocol members anyway.
3241
+ bool allowProtocolMembers = (dc->getSelfProtocolDecl () == nullptr );
3242
+
3224
3243
return directReferencesForTypeRepr (evaluator, dc->getASTContext (), typeRepr,
3225
3244
const_cast <DeclContext *>(dc),
3226
3245
/* allowUsableFromInline=*/ false ,
3227
- /* rhsOfSelfRequirement=*/ false );
3246
+ /* rhsOfSelfRequirement=*/ false ,
3247
+ allowProtocolMembers);
3228
3248
}
3229
3249
3230
3250
// Fall back to semantic types.
@@ -3245,7 +3265,8 @@ DirectlyReferencedTypeDecls UnderlyingTypeDeclsReferencedRequest::evaluate(
3245
3265
return directReferencesForTypeRepr (evaluator, typealias->getASTContext (),
3246
3266
typeRepr, typealias,
3247
3267
/* allowUsableFromInline=*/ false ,
3248
- /* rhsOfSelfRequirement=*/ false );
3268
+ /* rhsOfSelfRequirement=*/ false ,
3269
+ /* allowProtocolMembers=*/ true );
3249
3270
}
3250
3271
3251
3272
// Fall back to semantic types.
@@ -3404,7 +3425,8 @@ ExtendedNominalRequest::evaluate(Evaluator &evaluator,
3404
3425
DirectlyReferencedTypeDecls referenced =
3405
3426
directReferencesForTypeRepr (evaluator, ctx, typeRepr, ext->getParent (),
3406
3427
ext->isInSpecializeExtensionContext (),
3407
- /* rhsOfSelfRequirement=*/ false );
3428
+ /* rhsOfSelfRequirement=*/ false ,
3429
+ /* allowProtocolMembers=*/ true );
3408
3430
3409
3431
// Resolve those type declarations to nominal type declarations.
3410
3432
SmallVector<ModuleDecl *, 2 > modulesFound;
@@ -3454,7 +3476,8 @@ bool TypeRepr::isProtocolOrProtocolComposition(DeclContext *dc) {
3454
3476
auto &ctx = dc->getASTContext ();
3455
3477
auto references = directReferencesForTypeRepr (ctx.evaluator , ctx, this , dc,
3456
3478
/* allowUsableFromInline=*/ false ,
3457
- /* rhsOfSelfRequirement=*/ false );
3479
+ /* rhsOfSelfRequirement=*/ false ,
3480
+ /* allowProtocolMembers=*/ true );
3458
3481
return declsAreProtocols (references.first );
3459
3482
}
3460
3483
@@ -3489,7 +3512,8 @@ createTupleExtensionGenericParams(ASTContext &ctx,
3489
3512
extendedTypeRepr,
3490
3513
ext->getParent (),
3491
3514
/* allowUsableFromInline=*/ false ,
3492
- /* rhsOfSelfRequirement=*/ false );
3515
+ /* rhsOfSelfRequirement=*/ false ,
3516
+ /* allowProtocolMembers=*/ true );
3493
3517
assert (referenced.second .empty () && " Implement me" );
3494
3518
if (referenced.first .size () != 1 || !isa<TypeAliasDecl>(referenced.first [0 ]))
3495
3519
return nullptr ;
@@ -3764,7 +3788,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
3764
3788
decls = directReferencesForTypeRepr (
3765
3789
evaluator, ctx, typeRepr, dc,
3766
3790
/* allowUsableFromInline=*/ false ,
3767
- /* rhsOfSelfRequirement=*/ false );
3791
+ /* rhsOfSelfRequirement=*/ false ,
3792
+ /* allowProtocolMembers=*/ true );
3768
3793
} else if (Type type = attr->getType ()) {
3769
3794
decls = directReferencesForType (type);
3770
3795
}
@@ -3795,7 +3820,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
3795
3820
decls = directReferencesForUnqualifiedTypeLookup (
3796
3821
name, loc, dc, LookupOuterResults::Included,
3797
3822
/* allowUsableFromInline=*/ false ,
3798
- /* rhsOfSelfRequirement=*/ false );
3823
+ /* rhsOfSelfRequirement=*/ false ,
3824
+ /* allowProtocolMembers*/ true );
3799
3825
nominals = resolveTypeDeclsToNominal (evaluator, ctx, decls.first ,
3800
3826
ResolveToNominalOptions (),
3801
3827
modulesFound, anyObject);
@@ -4033,7 +4059,8 @@ ProtocolDecl *ImplementsAttrProtocolRequest::evaluate(
4033
4059
DirectlyReferencedTypeDecls referenced =
4034
4060
directReferencesForTypeRepr (evaluator, ctx, typeRepr, dc,
4035
4061
/* allowUsableFromInline=*/ false ,
4036
- /* rhsOfSelfRequirement=*/ false );
4062
+ /* rhsOfSelfRequirement=*/ false ,
4063
+ /* allowProtocolMembers=*/ true );
4037
4064
4038
4065
// Resolve those type declarations to nominal type declarations.
4039
4066
SmallVector<ModuleDecl *, 2 > modulesFound;
0 commit comments