File tree Expand file tree Collapse file tree 2 files changed +32
-16
lines changed Expand file tree Collapse file tree 2 files changed +32
-16
lines changed Original file line number Diff line number Diff line change @@ -314,15 +314,36 @@ CanPackType PackType::getReducedShape() {
314
314
}
315
315
316
316
CanType TypeBase::getReducedShape () {
317
- if (auto *packArchetype = getAs<PackArchetypeType>())
318
- return packArchetype->getReducedShape ();
319
-
320
317
if (auto *packType = getAs<PackType>())
321
318
return packType->getReducedShape ();
322
319
323
320
if (auto *expansionType = getAs<PackExpansionType>())
324
321
return expansionType->getReducedShape ();
325
322
323
+ struct PatternTypeWalker : public TypeWalker {
324
+ CanType shapeType;
325
+
326
+ Action walkToTypePre (Type type) override {
327
+ // Don't consider pack references inside nested pack
328
+ // expansion types.
329
+ if (type->is <PackExpansionType>()) {
330
+ return Action::Stop;
331
+ }
332
+
333
+ if (auto *archetype = type->getAs <PackArchetypeType>()) {
334
+ shapeType = archetype->getReducedShape ();
335
+ return Action::Stop;
336
+ }
337
+
338
+ return Action::Continue;
339
+ }
340
+ } patternTypeWalker;
341
+
342
+ Type (this ).walk (patternTypeWalker);
343
+
344
+ if (patternTypeWalker.shapeType )
345
+ return patternTypeWalker.shapeType ;
346
+
326
347
assert (!isTypeVariableOrMember ());
327
348
assert (!hasTypeParameter ());
328
349
Original file line number Diff line number Diff line change @@ -2925,20 +2925,15 @@ namespace {
2925
2925
CS.addConstraint (ConstraintKind::PackElementOf, elementResultType,
2926
2926
patternTy, CS.getConstraintLocator (expr));
2927
2927
2928
- // FIXME: Use a ShapeOf constraint here.
2929
- Type shapeType;
2930
- auto *binding = expr->getBindings ().front ();
2931
- auto type = CS.simplifyType (CS.getType (binding));
2932
- type.visit ([&](Type type) {
2933
- if (shapeType)
2934
- return ;
2935
-
2936
- if (auto archetype = type->getAs <PackArchetypeType>()) {
2937
- shapeType = archetype->getReducedShape ();
2938
- }
2939
- });
2928
+ auto *shapeLoc =
2929
+ CS.getConstraintLocator (expr, ConstraintLocator::PackShape);
2930
+ auto *shapeTypeVar = CS.createTypeVariable (shapeLoc,
2931
+ TVO_CanBindToPack |
2932
+ TVO_CanBindToHole);
2933
+ CS.addConstraint (ConstraintKind::ShapeOf, patternTy, shapeTypeVar,
2934
+ CS.getConstraintLocator (expr));
2940
2935
2941
- return PackExpansionType::get (patternTy, shapeType );
2936
+ return PackExpansionType::get (patternTy, shapeTypeVar );
2942
2937
}
2943
2938
2944
2939
Type visitDynamicTypeExpr (DynamicTypeExpr *expr) {
You can’t perform that action at this time.
0 commit comments