@@ -31,10 +31,18 @@ namespace {
31
31
// / skipping those captured by nested pack expansion types.
32
32
struct PackTypeParameterCollector : TypeWalker {
33
33
llvm::SetVector<Type> typeParams;
34
+ unsigned expansionLevel;
35
+ SmallVector<unsigned , 2 > elementLevel;
36
+
37
+ PackTypeParameterCollector () : expansionLevel(0 ) {
38
+ elementLevel.push_back (0 );
39
+ }
34
40
35
41
Action walkToTypePre (Type t) override {
36
- if (t->is <PackExpansionType>())
37
- return Action::SkipChildren;
42
+ if (t->is <PackExpansionType>()) {
43
+ ++expansionLevel;
44
+ return Action::Continue;
45
+ }
38
46
39
47
if (auto *boundGenericType = dyn_cast<BoundGenericType>(t.getPointer ())) {
40
48
if (auto parentType = boundGenericType->getParent ())
@@ -58,15 +66,32 @@ struct PackTypeParameterCollector: TypeWalker {
58
66
}
59
67
}
60
68
61
- if (auto *paramTy = t->getAs <GenericTypeParamType>()) {
62
- if (paramTy->isParameterPack ())
63
- typeParams.insert (paramTy);
64
- } else if (auto *archetypeTy = t->getAs <PackArchetypeType>()) {
65
- typeParams.insert (archetypeTy->getRoot ());
69
+ if (auto *eltType = t->getAs <PackElementType>()) {
70
+ elementLevel.push_back (eltType->getLevel ());
71
+ return Action::Continue;
72
+ }
73
+
74
+ if (elementLevel.back () == expansionLevel) {
75
+ if (auto *paramTy = t->getAs <GenericTypeParamType>()) {
76
+ if (paramTy->isParameterPack ())
77
+ typeParams.insert (paramTy);
78
+ } else if (auto *archetypeTy = t->getAs <PackArchetypeType>()) {
79
+ typeParams.insert (archetypeTy->getRoot ());
80
+ }
66
81
}
67
82
68
83
return Action::Continue;
69
84
}
85
+
86
+ Action walkToTypePost (Type t) override {
87
+ if (t->is <PackExpansionType>())
88
+ --expansionLevel;
89
+
90
+ if (t->is <PackElementType>())
91
+ elementLevel.pop_back ();
92
+
93
+ return Action::Continue;
94
+ }
70
95
};
71
96
72
97
}
0 commit comments