@@ -6575,6 +6575,42 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
6575
6575
}
6576
6576
6577
6577
case TypeKind::Tuple: {
6578
+ // FIXME: TuplePackMatcher doesn't correctly handle matching two
6579
+ // abstract contextual tuple types in a generic context.
6580
+ if (simplifyType(desugar1)->isEqual(simplifyType(desugar2)))
6581
+ return getTypeMatchSuccess();
6582
+
6583
+ // If the tuple has consecutive pack expansions, packs must be
6584
+ // resolved before matching.
6585
+ auto delayMatching = [](TupleType *tuple) {
6586
+ bool afterUnresolvedPack = false;
6587
+ for (auto element : tuple->getElements()) {
6588
+ if (afterUnresolvedPack && !element.hasName()) {
6589
+ return true;
6590
+ }
6591
+
6592
+ if (element.getType()->is<PackExpansionType>()) {
6593
+ SmallPtrSet<TypeVariableType *, 2> typeVars;
6594
+ element.getType()->getTypeVariables(typeVars);
6595
+
6596
+ afterUnresolvedPack = llvm::any_of(typeVars, [](auto *tv) {
6597
+ return tv->getImpl().canBindToPack();
6598
+ });
6599
+ } else {
6600
+ afterUnresolvedPack = false;
6601
+ }
6602
+ }
6603
+
6604
+ return false;
6605
+ };
6606
+
6607
+
6608
+ auto *tuple1 = cast<TupleType>(desugar1);
6609
+ auto *tuple2 = cast<TupleType>(desugar2);
6610
+ if (delayMatching(tuple1) || delayMatching(tuple2)) {
6611
+ return formUnsolvedResult();
6612
+ }
6613
+
6578
6614
// Add each tuple type to the locator before matching the element types.
6579
6615
// This is useful for diagnostics, because the error message can use the
6580
6616
// full tuple type for several element mismatches. Use the original types
0 commit comments