Skip to content

Commit 91af1d6

Browse files
committed
[AST] Use Type::transformRec() when getting a canonical type in context.
NFC cleanup
1 parent 3e3c81c commit 91af1d6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -605,21 +605,22 @@ CanType GenericSignature::getCanonicalTypeInContext(Type type,
605605
return CanType(type);
606606

607607
// Replace non-canonical type parameters.
608-
type = type.transform([&](Type component) -> Type {
609-
if (!component->isTypeParameter()) return component;
608+
type = type.transformRec([&](TypeBase *component) -> Optional<Type> {
609+
if (!isa<GenericTypeParamType>(component) &&
610+
!isa<DependentMemberType>(component))
611+
return None;
610612

611613
// Resolve the potential archetype. This can be null in nested generic
612614
// types, which we can't immediately canonicalize.
613-
auto pa = builder.resolveArchetype(component);
614-
if (!pa) return component;
615+
auto pa = builder.resolveArchetype(Type(component));
616+
if (!pa) return None;
615617

616618
auto rep = pa->getArchetypeAnchor();
617619
if (rep->isConcreteType()) {
618620
return getCanonicalTypeInContext(rep->getConcreteType(), builder);
619-
} else {
620-
return rep->getDependentType(getGenericParams(),
621-
/*allowUnresolved*/ false);
622621
}
622+
623+
return rep->getDependentType(getGenericParams(), /*allowUnresolved*/ false);
623624
});
624625

625626
auto result = type->getCanonicalType();

0 commit comments

Comments
 (0)