@@ -586,30 +586,8 @@ case TypeKind::Id:
586586 }
587587
588588 case TypeKind::PackExpansion: {
589- auto expand = cast<PackExpansionType>(base);
590-
591- // Substitution completely replaces this.
592-
593- Type transformedPat = doIt (expand->getPatternType (), pos);
594- if (!transformedPat)
595- return Type ();
596-
597- Type transformedCount = doIt (expand->getCountType (), TypePosition::Shape);
598- if (!transformedCount)
599- return Type ();
600-
601- if (transformedPat.getPointer () == expand->getPatternType ().getPointer () &&
602- transformedCount.getPointer () == expand->getCountType ().getPointer ())
603- return t;
604-
605- // // If we transform the count to a pack type, expand the pattern.
606- // // This is necessary because of how we piece together types in
607- // // the constraint system.
608- // if (auto countPack = transformedCount->getAs<PackType>()) {
609- // return PackExpansionType::expand(transformedPat, countPack);
610- // }
611-
612- return PackExpansionType::get (transformedPat, transformedCount);
589+ auto *expand = cast<PackExpansionType>(base);
590+ return asDerived ().transformPackExpansion (expand, pos);
613591 }
614592
615593 case TypeKind::PackElement: {
@@ -1005,8 +983,26 @@ case TypeKind::Id:
1005983 CanType transformSILField (CanType fieldTy, TypePosition pos) {
1006984 return doIt (fieldTy, pos)->getCanonicalType ();
1007985 }
986+
987+ Type transformPackExpansion (PackExpansionType *expand, TypePosition pos) {
988+ // Substitution completely replaces this.
989+
990+ Type transformedPat = doIt (expand->getPatternType (), pos);
991+ if (!transformedPat)
992+ return Type ();
993+
994+ Type transformedCount = doIt (expand->getCountType (), TypePosition::Shape);
995+ if (!transformedCount)
996+ return Type ();
997+
998+ if (transformedPat.getPointer () == expand->getPatternType ().getPointer () &&
999+ transformedCount.getPointer () == expand->getCountType ().getPointer ())
1000+ return expand;
1001+
1002+ return PackExpansionType::get (transformedPat, transformedCount);
1003+ }
10081004};
10091005
10101006}
10111007
1012- #endif
1008+ #endif
0 commit comments