Skip to content

Commit b011215

Browse files
committed
AST: Use transformTypeParameterPacks() in mapContextualPackTypeIntoElementContext()
1 parent 3064a00 commit b011215

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -672,35 +672,16 @@ GenericEnvironment::mapContextualPackTypeIntoElementContext(Type type) const {
672672
FindElementArchetypeForOpenedPackParam
673673
findElementArchetype(this, getOpenedPackParams());
674674

675-
return type.transformRec([&](TypeBase *ty) -> llvm::Optional<Type> {
676-
// We're only directly substituting pack archetypes.
677-
auto archetype = ty->getAs<PackArchetypeType>();
678-
if (!archetype) {
679-
// Don't recurse into nested pack expansions.
680-
if (ty->is<PackExpansionType>())
681-
return Type(ty);
682-
683-
// Recurse into any other type.
684-
return llvm::None;
685-
}
686-
687-
auto rootArchetype = cast<PackArchetypeType>(archetype->getRoot());
688-
689-
// TODO: assert that the generic environment of the pack archetype
690-
// matches the signature that was originally opened to make this
691-
// environment. Unfortunately, that isn't a trivial check because of
692-
// the extra opened-element parameters.
693-
694-
// If the archetype isn't the shape that was opened by this
695-
// environment, ignore it.
696-
auto rootParam = cast<GenericTypeParamType>(
697-
rootArchetype->getInterfaceType().getPointer());
698-
assert(rootParam->isParameterPack());
699-
if (!sig->haveSameShape(rootParam, shapeClass))
700-
return Type(ty);
701-
702-
return Type(findElementArchetype(archetype->getInterfaceType()));
703-
});
675+
return type.transformTypeParameterPacks(
676+
[&](SubstitutableType *ty) -> llvm::Optional<Type> {
677+
if (auto *packArchetype = dyn_cast<PackArchetypeType>(ty)) {
678+
auto interfaceType = packArchetype->getInterfaceType();
679+
if (sig->haveSameShape(interfaceType, shapeClass))
680+
return Type(findElementArchetype(interfaceType));
681+
}
682+
683+
return llvm::None;
684+
});
704685
}
705686

706687
CanType

0 commit comments

Comments
 (0)