@@ -104,7 +104,8 @@ GenericEnvironment::getPackElementContextSubstitutions() const {
104104 return environmentData->outerSubstitutions ;
105105}
106106
107- CanType GenericEnvironment::getOpenedElementShapeClass () const {
107+ CanGenericTypeParamType
108+ GenericEnvironment::getOpenedElementShapeClass () const {
108109 assert (getKind () == Kind::OpenedElement);
109110 auto environmentData = getTrailingObjects<OpenedElementEnvironmentData>();
110111 return environmentData->shapeClass ;
@@ -160,7 +161,7 @@ void GenericEnvironment::forEachPackElementGenericTypeParam(
160161
161162 // Only include opened element parameters for packs in the given
162163 // shape equivalence class.
163- if (!sig->haveSameShape (genericParam, shapeClass-> mapTypeOutOfContext () ))
164+ if (!sig->haveSameShape (genericParam, shapeClass))
164165 continue ;
165166
166167 function (genericParam);
@@ -218,7 +219,8 @@ GenericEnvironment::GenericEnvironment(
218219}
219220
220221GenericEnvironment::GenericEnvironment (GenericSignature signature,
221- UUID uuid, CanType shapeClass,
222+ UUID uuid,
223+ CanGenericTypeParamType shapeClass,
222224 SubstitutionMap outerSubs)
223225 : SignatureAndKind(signature, Kind::OpenedElement)
224226{
@@ -627,7 +629,7 @@ GenericEnvironment::mapPackTypeIntoElementContext(Type type) const {
627629 if (!genericParam->isParameterPack ())
628630 continue ;
629631
630- if (!sig->haveSameShape (genericParam, shapeClass-> mapTypeOutOfContext () ))
632+ if (!sig->haveSameShape (genericParam, shapeClass))
631633 continue ;
632634
633635 auto elementIndex = elementParamForPack.size ();
@@ -680,7 +682,7 @@ GenericEnvironment::mapElementTypeIntoPackContext(Type type) const {
680682 if (!genericParam->isParameterPack ())
681683 continue ;
682684
683- if (!sig->haveSameShape (genericParam, shapeClass-> mapTypeOutOfContext () ))
685+ if (!sig->haveSameShape (genericParam, shapeClass))
684686 continue ;
685687
686688 GenericParamKey elementKey (/* isParameterPack*/ false ,
@@ -767,16 +769,19 @@ OpenedElementContext::createForContextualExpansion(ASTContext &ctx,
767769 " must be given a contextual type" );
768770
769771 // Get the outer generic signature and environment.
770- auto *genericEnv = cast<ArchetypeType>(expansionType.getCountType ())
771- ->getGenericEnvironment ();
772+ auto countArchetype = cast<ArchetypeType>(expansionType.getCountType ());
773+ auto *genericEnv = countArchetype ->getGenericEnvironment ();
772774 auto subMap = genericEnv->getForwardingSubstitutionMap ();
773775
776+ auto countType = cast<GenericTypeParamType>(
777+ countArchetype->getInterfaceType ()->getCanonicalType ());
778+
774779 auto genericSig = genericEnv->getGenericSignature ().getCanonicalSignature ();
775780 // Create an opened element signature and environment.
776781 auto elementSig = ctx.getOpenedElementSignature (
777- genericSig, expansionType. getCountType () );
782+ genericSig, countType );
778783 auto *elementEnv = GenericEnvironment::forOpenedElement (
779- elementSig, UUID::fromTime (), expansionType. getCountType () , subMap);
784+ elementSig, UUID::fromTime (), countType , subMap);
780785
781786 return {elementEnv, elementSig};
782787}
0 commit comments