Skip to content

Commit c624ff5

Browse files
committed
ClangImporter: Fix finishTypeWitnesses() to work with protocol typealiases
1 parent 1023b1c commit c624ff5

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7337,8 +7337,12 @@ void ClangImporter::Implementation::finishPendingActions() {
73377337
/// Look up associated type requirements in the conforming type.
73387338
static void finishTypeWitnesses(
73397339
NormalProtocolConformance *conformance) {
7340+
auto *dc = conformance->getDeclContext();
7341+
auto *module = dc->getParentModule();
7342+
auto &ctx = module->getASTContext();
7343+
73407344
auto *proto = conformance->getProtocol();
7341-
auto *nominal = conformance->getType()->getAnyNominal();
7345+
auto selfType = conformance->getType();
73427346

73437347
for (auto *req : proto->getMembers()) {
73447348
if (auto *assocType = dyn_cast<AssociatedTypeDecl>(req)) {
@@ -7347,14 +7351,22 @@ static void finishTypeWitnesses(
73477351

73487352
bool satisfied = false;
73497353

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);
73587370
satisfied = true;
73597371
break;
73607372
}

0 commit comments

Comments
 (0)