24
24
25
25
using namespace swift ;
26
26
27
- static Type createPackBinding (ASTContext &ctx, ArrayRef<Type> types) {
28
- // If there is only one element and it's a pack expansion type,
29
- // return the pattern type directly. Because PackType can only appear
30
- // inside a PackExpansion, PackType(PackExpansionType()) will always
31
- // simplify to the pattern type.
27
+ static PackExpansionType *createPackBinding (ASTContext &ctx,
28
+ ArrayRef<Type> types) {
29
+ // If there is only one element and it's a PackExpansionType,
30
+ // return it directly.
32
31
if (types.size () == 1 ) {
33
- if (types.front ()->is <PackExpansionType>()) {
34
- return types. front () ;
32
+ if (auto *expansionType = types.front ()->getAs <PackExpansionType>()) {
33
+ return expansionType ;
35
34
}
36
35
}
37
36
37
+ // Otherwise, wrap the elements in PackExpansionType(PackType(...)).
38
38
auto *packType = PackType::get (ctx, types);
39
39
return PackExpansionType::get (packType, packType);
40
40
}
41
41
42
- static Type gatherTupleElements (ArrayRef<TupleTypeElt> &elts,
43
- Identifier name,
44
- ASTContext &ctx) {
42
+ static PackExpansionType * gatherTupleElements (ArrayRef<TupleTypeElt> &elts,
43
+ Identifier name,
44
+ ASTContext &ctx) {
45
45
SmallVector<Type, 2 > types;
46
46
47
47
if (!elts.empty () && elts.front ().getName () == name) {
@@ -190,7 +190,7 @@ bool ParamPackMatcher::match() {
190
190
// to what remains of the right hand side.
191
191
if (lhsParams.size () == 1 ) {
192
192
auto lhsType = lhsParams[0 ].getPlainType ();
193
- if (lhsType->is <PackExpansionType>()) {
193
+ if (auto *lhsExpansion = lhsType->getAs <PackExpansionType>()) {
194
194
SmallVector<Type, 2 > rhsTypes;
195
195
for (auto rhsParam : rhsParams) {
196
196
// FIXME: Check rhs flags
@@ -199,7 +199,7 @@ bool ParamPackMatcher::match() {
199
199
auto rhs = createPackBinding (ctx, rhsTypes);
200
200
201
201
// FIXME: Check lhs flags
202
- pairs.emplace_back (lhsType , rhs, prefixLength);
202
+ pairs.emplace_back (lhsExpansion , rhs, prefixLength);
203
203
return false ;
204
204
}
205
205
}
@@ -208,7 +208,7 @@ bool ParamPackMatcher::match() {
208
208
// to what remains of the left hand side.
209
209
if (rhsParams.size () == 1 ) {
210
210
auto rhsType = rhsParams[0 ].getPlainType ();
211
- if (rhsType->is <PackExpansionType>()) {
211
+ if (auto *rhsExpansion = rhsType->getAs <PackExpansionType>()) {
212
212
SmallVector<Type, 2 > lhsTypes;
213
213
for (auto lhsParam : lhsParams) {
214
214
// FIXME: Check lhs flags
@@ -217,7 +217,7 @@ bool ParamPackMatcher::match() {
217
217
auto lhs = createPackBinding (ctx, lhsTypes);
218
218
219
219
// FIXME: Check rhs flags
220
- pairs.emplace_back (lhs, rhsType , prefixLength);
220
+ pairs.emplace_back (lhs, rhsExpansion , prefixLength);
221
221
return false ;
222
222
}
223
223
}
@@ -287,10 +287,10 @@ bool PackMatcher::match() {
287
287
// to what remains of the right hand side.
288
288
if (lhsTypes.size () == 1 ) {
289
289
auto lhsType = lhsTypes[0 ];
290
- if (lhsType->is <PackExpansionType>()) {
290
+ if (auto *lhsExpansion = lhsType->getAs <PackExpansionType>()) {
291
291
auto rhs = createPackBinding (ctx, rhsTypes);
292
292
293
- pairs.emplace_back (lhsType , rhs, prefixLength);
293
+ pairs.emplace_back (lhsExpansion , rhs, prefixLength);
294
294
return false ;
295
295
}
296
296
}
@@ -299,10 +299,10 @@ bool PackMatcher::match() {
299
299
// to what remains of the left hand side.
300
300
if (rhsTypes.size () == 1 ) {
301
301
auto rhsType = rhsTypes[0 ];
302
- if (rhsType->is <PackExpansionType>()) {
302
+ if (auto *rhsExpansion = rhsType->getAs <PackExpansionType>()) {
303
303
auto lhs = createPackBinding (ctx, lhsTypes);
304
304
305
- pairs.emplace_back (lhs, rhsType , prefixLength);
305
+ pairs.emplace_back (lhs, rhsExpansion , prefixLength);
306
306
return false ;
307
307
}
308
308
}
0 commit comments