@@ -7337,8 +7337,12 @@ void ClangImporter::Implementation::finishPendingActions() {
7337
7337
// / Look up associated type requirements in the conforming type.
7338
7338
static void finishTypeWitnesses (
7339
7339
NormalProtocolConformance *conformance) {
7340
+ auto *dc = conformance->getDeclContext ();
7341
+ auto *module = dc->getParentModule ();
7342
+ auto &ctx = module ->getASTContext ();
7343
+
7340
7344
auto *proto = conformance->getProtocol ();
7341
- auto *nominal = conformance->getType ()-> getAnyNominal ();
7345
+ auto selfType = conformance->getType ();
7342
7346
7343
7347
for (auto *req : proto->getMembers ()) {
7344
7348
if (auto *assocType = dyn_cast<AssociatedTypeDecl>(req)) {
@@ -7347,14 +7351,22 @@ static void finishTypeWitnesses(
7347
7351
7348
7352
bool satisfied = false ;
7349
7353
7350
- for (auto member : nominal->lookupDirect (assocType->getFullName ())) {
7351
- auto memberType = dyn_cast<TypeDecl>(member);
7352
- if (!memberType) continue ;
7353
-
7354
- conformance->setTypeWitness (assocType,
7355
- nominal->mapTypeIntoContext (
7356
- memberType->getDeclaredInterfaceType ()),
7357
- memberType);
7354
+ SmallVector<ValueDecl *, 4 > lookupResults;
7355
+ NLOptions options = (NL_QualifiedDefault |
7356
+ NL_OnlyTypes |
7357
+ NL_ProtocolMembers);
7358
+
7359
+ dc->lookupQualified (selfType, assocType->getFullName (), options,
7360
+ ctx.getLazyResolver (), lookupResults);
7361
+ for (auto member : lookupResults) {
7362
+ auto typeDecl = cast<TypeDecl>(member);
7363
+ if (isa<AssociatedTypeDecl>(typeDecl)) continue ;
7364
+
7365
+ auto memberType = typeDecl->getDeclaredInterfaceType ();
7366
+ auto subMap = selfType->getContextSubstitutionMap (
7367
+ module , typeDecl->getDeclContext ());
7368
+ memberType = memberType.subst (subMap);
7369
+ conformance->setTypeWitness (assocType, memberType, typeDecl);
7358
7370
satisfied = true ;
7359
7371
break ;
7360
7372
}
0 commit comments