@@ -116,6 +116,29 @@ class ContainsSpecializableArchetype : public TypeWalker {
116
116
}
117
117
};
118
118
119
+ // / Returns `true` if `ED` is an extension of `BaseTy` that binds `Self` to a
120
+ // / concrete type, like `extension MyProto where Self == MyStruct {}`.
121
+ // /
122
+ // / In these cases, it is possible to access static members defined in the
123
+ // / extension when perfoming unresolved member lookup in a type context of
124
+ // / `BaseType`.
125
+ static bool isExtensionWithSelfBound (const ExtensionDecl *ED, Type BaseTy) {
126
+ if (!ED) {
127
+ return false ;
128
+ }
129
+ GenericSignature genericSig = ED->getGenericSignature ();
130
+ if (!ED->getExtendedType ()->isEqual (BaseTy)) {
131
+ return false ;
132
+ }
133
+ if (!ED->getSelfInterfaceType ()->isTypeParameter ()) {
134
+ return false ;
135
+ }
136
+ if (!genericSig->getConcreteType (ED->getSelfInterfaceType ())) {
137
+ return false ;
138
+ }
139
+ return true ;
140
+ }
141
+
119
142
static bool isExtensionAppliedInternal (const DeclContext *DC, Type BaseTy,
120
143
const ExtensionDecl *ED) {
121
144
// We can't do anything if the base type has unbound generic parameters.
@@ -131,6 +154,9 @@ static bool isExtensionAppliedInternal(const DeclContext *DC, Type BaseTy,
131
154
return true ;
132
155
133
156
GenericSignature genericSig = ED->getGenericSignature ();
157
+ if (isExtensionWithSelfBound (ED, BaseTy)) {
158
+ return true ;
159
+ }
134
160
auto *module = DC->getParentModule ();
135
161
SubstitutionMap substMap = BaseTy->getContextSubstitutionMap (
136
162
module , ED->getExtendedNominal ());
@@ -142,7 +168,9 @@ static bool isExtensionAppliedInternal(const DeclContext *DC, Type BaseTy,
142
168
143
169
static bool isMemberDeclAppliedInternal (const DeclContext *DC, Type BaseTy,
144
170
const ValueDecl *VD) {
145
- if (BaseTy->isExistentialType () && VD->isStatic ())
171
+ if (BaseTy->isExistentialType () && VD->isStatic () &&
172
+ !isExtensionWithSelfBound (dyn_cast<ExtensionDecl>(VD->getDeclContext ()),
173
+ BaseTy))
146
174
return false ;
147
175
148
176
// We can't leak type variables into another constraint system.
0 commit comments