Skip to content

Commit c7ef47d

Browse files
committed
[ConstraintSystem] TypeSimplifier: Prevent flattening of partially resolved pack expansions
If a pattern type of a pack expansion doesn't have all of the "pack capable" type variables bound, we don't know what the structure is yet and expansion cannot be flattened.
1 parent 39c2bbb commit c7ef47d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3791,9 +3791,25 @@ struct TypeSimplifier {
37913791
}
37923792

37933793
if (auto expansion = dyn_cast<PackExpansionType>(type.getPointer())) {
3794+
// First, let's check whether pattern type has all of the type variables
3795+
// that represent packs resolved, otherwise we don't have enough information
3796+
// to flatten this pack expansion type.
3797+
//
3798+
// Note that we don't actually need to do deep transformation here
3799+
// because pack variables can only appear in structural positions.
3800+
if (expansion->getPatternType().findIf([&](Type type) {
3801+
if (auto *typeVar = type->getAs<TypeVariableType>()) {
3802+
if (typeVar->getImpl().canBindToPack())
3803+
return GetFixedTypeFn(typeVar)->is<TypeVariableType>();
3804+
}
3805+
return false;
3806+
})) {
3807+
return expansion;
3808+
}
3809+
37943810
// Transform the count type, ignoring any active pack expansions.
37953811
auto countType = expansion->getCountType().transform(
3796-
TypeSimplifier(CS, GetFixedTypeFn));
3812+
TypeSimplifier(CS, GetFixedTypeFn));
37973813

37983814
if (auto countPack = countType->getAs<PackType>()) {
37993815
SmallVector<Type, 4> elts;

0 commit comments

Comments
 (0)