Skip to content

Commit b4820a0

Browse files
committed
[CSSimplify] Delay matching tuple types with at least 2 elements until
all pack type variables are resolved.
1 parent 41448ba commit b4820a0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6575,6 +6575,26 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
65756575
}
65766576

65776577
case TypeKind::Tuple: {
6578+
auto type1 = simplifyType(desugar1)->getDesugaredType();
6579+
auto type2 = simplifyType(desugar2)->getDesugaredType();
6580+
6581+
// FIXME: TuplePackMatcher doesn't correctly handle matching two
6582+
// abstract contextual tuple types in a generic context.
6583+
if (type1->isEqual(type2))
6584+
return getTypeMatchSuccess();
6585+
6586+
// If the tuple has more than one element, packs must be
6587+
// resolved before matching.
6588+
SmallPtrSet<TypeVariableType *, 2> typeVars;
6589+
type1->getTypeVariables(typeVars);
6590+
type2->getTypeVariables(typeVars);
6591+
if (desugar1->getAs<TupleType>()->getNumElements() > 1 &&
6592+
llvm::any_of(typeVars, [](auto *tv) {
6593+
return tv->getImpl().canBindToPack();
6594+
})) {
6595+
return formUnsolvedResult();
6596+
}
6597+
65786598
// Add each tuple type to the locator before matching the element types.
65796599
// This is useful for diagnostics, because the error message can use the
65806600
// full tuple type for several element mismatches. Use the original types

0 commit comments

Comments
 (0)