[ConstraintSystem] Use reduced shape types when generating constraints for pack

expansion expressions.
This commit is contained in:
Holly Borla
2022-10-23 20:25:38 -07:00
parent 45722bf277
commit 13a17ef918
3 changed files with 21 additions and 3 deletions

View File

@@ -2889,9 +2889,17 @@ namespace {
auto patternTy = CS.getType(expr->getPatternExpr());
// FIXME: Use a ShapeOf constraint here.
auto *declRef = dyn_cast<DeclRefExpr>(expr->getBindings().front());
auto *decl = dyn_cast<VarDecl>(declRef->getDecl());
auto shapeType = decl->getType()->getAs<PackExpansionType>()->getCountType();
Type shapeType;
auto *binding = expr->getBindings().front();
auto type = CS.simplifyType(CS.getType(binding));
type.visit([&](Type type) {
if (shapeType)
return;
if (auto archetype = type->getAs<PackArchetypeType>()) {
shapeType = CS.DC->mapTypeIntoContext(archetype->getShape());
}
});
return PackExpansionType::get(patternTy, shapeType);
}