@@ -672,35 +672,16 @@ GenericEnvironment::mapContextualPackTypeIntoElementContext(Type type) const {
672
672
FindElementArchetypeForOpenedPackParam
673
673
findElementArchetype (this , getOpenedPackParams ());
674
674
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
+ });
704
685
}
705
686
706
687
CanType
0 commit comments