@@ -30,12 +30,13 @@ static Type createPackBinding(ASTContext &ctx, ArrayRef<Type> types) {
30
30
// inside a PackExpansion, PackType(PackExpansionType()) will always
31
31
// simplify to the pattern type.
32
32
if (types.size () == 1 ) {
33
- if (auto *expansion = types.front ()->getAs <PackExpansionType>()) {
34
- return expansion-> getPatternType ();
33
+ if (types.front ()->is <PackExpansionType>()) {
34
+ return types. front ();
35
35
}
36
36
}
37
37
38
- return PackType::get (ctx, types);
38
+ auto *packType = PackType::get (ctx, types);
39
+ return PackExpansionType::get (packType, packType);
39
40
}
40
41
41
42
static Type gatherTupleElements (ArrayRef<TupleTypeElt> &elts,
@@ -84,7 +85,7 @@ bool TuplePackMatcher::match() {
84
85
" by an unlabeled element" );
85
86
86
87
auto rhs = gatherTupleElements (rhsElts, lhsElt.getName (), ctx);
87
- pairs.emplace_back (lhsExpansionType-> getPatternType () , rhs, idx++);
88
+ pairs.emplace_back (lhsExpansionType, rhs, idx++);
88
89
continue ;
89
90
}
90
91
@@ -104,7 +105,7 @@ bool TuplePackMatcher::match() {
104
105
" by an unlabeled element" );
105
106
106
107
auto lhs = gatherTupleElements (lhsElts, rhsElt.getName (), ctx);
107
- pairs.emplace_back (lhs, rhsExpansionType-> getPatternType () , idx++);
108
+ pairs.emplace_back (lhs, rhsExpansionType, idx++);
108
109
continue ;
109
110
}
110
111
@@ -189,16 +190,16 @@ bool ParamPackMatcher::match() {
189
190
// to what remains of the right hand side.
190
191
if (lhsParams.size () == 1 ) {
191
192
auto lhsType = lhsParams[0 ].getPlainType ();
192
- if (auto *lhsExpansionType = lhsType->getAs <PackExpansionType>()) {
193
+ if (lhsType->is <PackExpansionType>()) {
193
194
SmallVector<Type, 2 > rhsTypes;
194
195
for (auto rhsParam : rhsParams) {
195
196
// FIXME: Check rhs flags
196
197
rhsTypes.push_back (rhsParam.getPlainType ());
197
198
}
198
- auto rhs = PackType::get (ctx, rhsTypes);
199
+ auto rhs = createPackBinding (ctx, rhsTypes);
199
200
200
201
// FIXME: Check lhs flags
201
- pairs.emplace_back (lhsExpansionType-> getPatternType () , rhs, prefixLength);
202
+ pairs.emplace_back (lhsType , rhs, prefixLength);
202
203
return false ;
203
204
}
204
205
}
@@ -207,13 +208,13 @@ bool ParamPackMatcher::match() {
207
208
// to what remains of the left hand side.
208
209
if (rhsParams.size () == 1 ) {
209
210
auto rhsType = rhsParams[0 ].getPlainType ();
210
- if (auto *rhsExpansionType = rhsType->getAs <PackExpansionType>()) {
211
+ if (rhsType->is <PackExpansionType>()) {
211
212
SmallVector<Type, 2 > lhsTypes;
212
213
for (auto lhsParam : lhsParams) {
213
214
// FIXME: Check lhs flags
214
215
lhsTypes.push_back (lhsParam.getPlainType ());
215
216
}
216
- auto lhs = PackType::get (ctx, lhsTypes);
217
+ auto lhs = createPackBinding (ctx, lhsTypes);
217
218
218
219
// FIXME: Check rhs flags
219
220
pairs.emplace_back (lhs, rhsType, prefixLength);
@@ -286,10 +287,10 @@ bool PackMatcher::match() {
286
287
// to what remains of the right hand side.
287
288
if (lhsTypes.size () == 1 ) {
288
289
auto lhsType = lhsTypes[0 ];
289
- if (auto *lhsExpansionType = lhsType->getAs <PackExpansionType>()) {
290
- auto rhs = PackType::get (ctx, rhsTypes);
290
+ if (lhsType->is <PackExpansionType>()) {
291
+ auto rhs = createPackBinding (ctx, rhsTypes);
291
292
292
- pairs.emplace_back (lhsExpansionType-> getPatternType () , rhs, prefixLength);
293
+ pairs.emplace_back (lhsType , rhs, prefixLength);
293
294
return false ;
294
295
}
295
296
}
@@ -298,8 +299,8 @@ bool PackMatcher::match() {
298
299
// to what remains of the left hand side.
299
300
if (rhsTypes.size () == 1 ) {
300
301
auto rhsType = rhsTypes[0 ];
301
- if (auto *rhsExpansionType = rhsType->getAs <PackExpansionType>()) {
302
- auto lhs = PackType::get (ctx, lhsTypes);
302
+ if (rhsType->is <PackExpansionType>()) {
303
+ auto lhs = createPackBinding (ctx, lhsTypes);
303
304
304
305
pairs.emplace_back (lhs, rhsType, prefixLength);
305
306
return false ;
0 commit comments