@@ -2206,7 +2206,18 @@ class SubstFunctionTypePatternVisitor
2206
2206
auto patternTy = visit (substPatternType, origPatternType);
2207
2207
2208
2208
// 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
+ });
2210
2221
2211
2222
// If that didn't work, we should be able to find an expansion
2212
2223
// to use from either the substituted type or the subs. At worst,
@@ -2216,37 +2227,6 @@ class SubstFunctionTypePatternVisitor
2216
2227
return CanPackExpansionType::get (patternTy, countParam);
2217
2228
}
2218
2229
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
-
2250
2230
CanType visitExistentialType (CanExistentialType exist,
2251
2231
AbstractionPattern pattern) {
2252
2232
// Avoid walking into the constraint type if we can help it.
0 commit comments