@@ -2206,7 +2206,18 @@ class SubstFunctionTypePatternVisitor
22062206 auto patternTy = visit (substPatternType, origPatternType);
22072207
22082208 // Find a pack parameter from the pattern to expand over.
2209- auto countParam = findExpandedPackParameter (patternTy);
2209+ CanType countParam;
2210+ patternTy->walkPackReferences ([&](Type t) {
2211+ if (t->isTypeParameter ()) {
2212+ auto param = t->getRootGenericParam ();
2213+ if (param->isParameterPack ()) {
2214+ countParam = CanType (param);
2215+ return true ;
2216+ }
2217+ }
2218+
2219+ return false ;
2220+ });
22102221
22112222 // If that didn't work, we should be able to find an expansion
22122223 // to use from either the substituted type or the subs. At worst,
@@ -2216,37 +2227,6 @@ class SubstFunctionTypePatternVisitor
22162227 return CanPackExpansionType::get (patternTy, countParam);
22172228 }
22182229
2219- static CanType findExpandedPackParameter (CanType patternType) {
2220- struct Walker : public TypeWalker {
2221- CanType Result;
2222- Action walkToTypePre (Type _ty) override {
2223- auto ty = CanType (_ty);
2224-
2225- // Don't recurse inside pack expansions.
2226- if (isa<PackExpansionType>(ty)) {
2227- return Action::SkipChildren;
2228- }
2229-
2230- // Consider type parameters.
2231- if (ty->isTypeParameter ()) {
2232- auto param = ty->getRootGenericParam ();
2233- if (param->isParameterPack ()) {
2234- Result = CanType (param);
2235- return Action::Stop;
2236- }
2237- return Action::SkipChildren;
2238- }
2239-
2240- // Otherwise continue.
2241- return Action::Continue;
2242- }
2243- };
2244-
2245- Walker walker;
2246- patternType.walk (walker);
2247- return walker.Result ;
2248- }
2249-
22502230 CanType visitExistentialType (CanExistentialType exist,
22512231 AbstractionPattern pattern) {
22522232 // Avoid walking into the constraint type if we can help it.
0 commit comments