Skip to content

Commit 3b8e9df

Browse files
committed
Use the generic signature to find nested types by name.
1 parent 590331d commit 3b8e9df

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/AST/Type.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,14 +3703,11 @@ Type ArchetypeType::getNestedType(AssociatedTypeDecl *assocType) {
37033703
}
37043704

37053705
Type ArchetypeType::getNestedTypeByName(Identifier name) {
3706-
AssociatedTypeDecl *assocType = nullptr;
3707-
ProtocolType::visitAllProtocols(getConformsTo(), [&](ProtocolDecl *proto) {
3708-
assocType = proto->getAssociatedType(name);
3709-
return assocType != nullptr;
3710-
});
3711-
3712-
if (assocType)
3706+
auto memberDecl = getGenericEnvironment()->getGenericSignature()
3707+
->lookupNestedType(getInterfaceType(), name);
3708+
if (auto assocType = dyn_cast_or_null<AssociatedTypeDecl>(memberDecl)) {
37133709
return getNestedType(assocType);
3710+
}
37143711

37153712
return Type();
37163713
}
@@ -3920,10 +3917,6 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
39203917
// If the parent is an archetype, extract the child archetype with the
39213918
// given name.
39223919
if (auto archetypeParent = substBase->getAs<ArchetypeType>()) {
3923-
// if (assocType && !archetypeParent->getSuperclass())
3924-
// return archetypeParent->getNestedType(assocType);
3925-
3926-
// FIXME: This is really slow for the case where we have an associated type.
39273920
if (Type memberArchetypeByName = archetypeParent->getNestedTypeByName(name))
39283921
return memberArchetypeByName;
39293922

0 commit comments

Comments
 (0)