Skip to content

Commit 5985275

Browse files
committed
[ConstraintSystem] TypeSimplifier: Unwrap tuple if pack expansion variable is flattened
This is effectively the same as check `transformWithPosition` but handles pack expansion type variables.
1 parent f4a082d commit 5985275

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,11 +3779,25 @@ struct TypeSimplifier {
37793779
if (auto tuple = dyn_cast<TupleType>(type.getPointer())) {
37803780
if (tuple->getNumElements() == 1) {
37813781
auto element = tuple->getElement(0);
3782-
auto elementType = element.getType().transform(*this);
3782+
auto elementType = element.getType();
3783+
auto resolvedType = elementType.transform(*this);
3784+
3785+
// If this is a single-element tuple with pack expansion
3786+
// variable inside, let's unwrap it if pack is flattened.
3787+
if (!element.hasName()) {
3788+
if (auto *typeVar = elementType->getAs<TypeVariableType>()) {
3789+
if (typeVar->getImpl().isPackExpansion() &&
3790+
!resolvedType->isEqual(typeVar) &&
3791+
!resolvedType->is<PackExpansionType>() &&
3792+
!resolvedType->is<PackType>()) {
3793+
return resolvedType;
3794+
}
3795+
}
3796+
}
37833797

37843798
// Flatten single-element tuples containing type variables that cannot
37853799
// bind to packs.
3786-
auto typeVar = elementType->getAs<TypeVariableType>();
3800+
auto typeVar = resolvedType->getAs<TypeVariableType>();
37873801
if (!element.hasName() && typeVar &&
37883802
!typeVar->getImpl().canBindToPack() &&
37893803
!typeVar->getImpl().isPackExpansion()) {

0 commit comments

Comments
 (0)