@@ -129,6 +129,12 @@ namespace {
129
129
130
130
assert (isa<ProtocolDecl>(foundDC));
131
131
132
+ if (!Options.contains (NameLookupFlags::PerformConformanceCheck))
133
+ return ;
134
+
135
+ // If we found something within the protocol itself, and our
136
+ // search began somewhere that is not in a protocol or extension
137
+ // thereof, remap this declaration to the witness.
132
138
auto conformingType = foundInType;
133
139
134
140
// When performing a lookup on a subclass existential, we might
@@ -143,52 +149,43 @@ namespace {
143
149
conformingType = layout.superclass ;
144
150
}
145
151
146
- // If we found something within the protocol itself, and our
147
- // search began somewhere that is not in a protocol or extension
148
- // thereof, remap this declaration to the witness.
149
- if (foundInType->is <ArchetypeType>() ||
150
- foundInType->isExistentialType () ||
151
- Options.contains (NameLookupFlags::PerformConformanceCheck)) {
152
- // Dig out the protocol conformance.
153
- auto conformance = TC.conformsToProtocol (conformingType, foundProto, DC,
152
+ // Dig out the protocol conformance.
153
+ auto conformance = TC.conformsToProtocol (conformingType, foundProto, DC,
154
154
conformanceOptions);
155
- if (!conformance) {
156
- // If there's no conformance, we have an existential
157
- // and we found a member from one of the protocols, and
158
- // not a class constraint if any.
159
- assert (foundInType->isExistentialType ());
160
- addResult (found);
161
- return ;
162
- }
163
-
164
- if (conformance->isAbstract ()) {
165
- assert (foundInType->is <ArchetypeType>() ||
166
- foundInType->isExistentialType ());
167
- addResult (found);
168
- return ;
169
- }
170
-
171
- // Dig out the witness.
172
- ValueDecl *witness = nullptr ;
173
- auto concrete = conformance->getConcrete ();
174
- if (auto assocType = dyn_cast<AssociatedTypeDecl>(found)) {
175
- witness = concrete->getTypeWitnessAndDecl (assocType, &TC)
176
- .second ;
177
- } else if (found->isProtocolRequirement ()) {
178
- witness = concrete->getWitnessDecl (found, &TC);
179
- }
180
-
181
- // FIXME: the "isa<ProtocolDecl>()" check will be wrong for
182
- // default implementations in protocols.
183
- //
184
- // If we have an imported conformance or the witness could
185
- // not be deserialized, getWitnessDecl() will just return
186
- // the requirement, so just drop the lookup result here.
187
- if (witness && !isa<ProtocolDecl>(witness->getDeclContext ()))
188
- addResult (witness);
155
+ if (!conformance) {
156
+ // If there's no conformance, we have an existential
157
+ // and we found a member from one of the protocols, and
158
+ // not a class constraint if any.
159
+ assert (foundInType->isExistentialType ());
160
+ addResult (found);
161
+ return ;
162
+ }
189
163
164
+ if (conformance->isAbstract ()) {
165
+ assert (foundInType->is <ArchetypeType>() ||
166
+ foundInType->isExistentialType ());
167
+ addResult (found);
190
168
return ;
191
169
}
170
+
171
+ // Dig out the witness.
172
+ ValueDecl *witness = nullptr ;
173
+ auto concrete = conformance->getConcrete ();
174
+ if (auto assocType = dyn_cast<AssociatedTypeDecl>(found)) {
175
+ witness = concrete->getTypeWitnessAndDecl (assocType, &TC)
176
+ .second ;
177
+ } else if (found->isProtocolRequirement ()) {
178
+ witness = concrete->getWitnessDecl (found, &TC);
179
+ }
180
+
181
+ // FIXME: the "isa<ProtocolDecl>()" check will be wrong for
182
+ // default implementations in protocols.
183
+ //
184
+ // If we have an imported conformance or the witness could
185
+ // not be deserialized, getWitnessDecl() will just return
186
+ // the requirement, so just drop the lookup result here.
187
+ if (witness && !isa<ProtocolDecl>(witness->getDeclContext ()))
188
+ addResult (witness);
192
189
}
193
190
};
194
191
} // end anonymous namespace
0 commit comments