@@ -1547,6 +1547,9 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
15471547 SmallVector<LocatorPathElt, 4 > path;
15481548 (void )locator.getLocatorParts (path);
15491549
1550+ while (!path.empty () && path.back ().is <LocatorPathElt::TupleType>())
1551+ path.pop_back ();
1552+
15501553 if (!path.empty ()) {
15511554 // Direct pattern matching between tuple pattern and tuple type.
15521555 if (path.back ().is <LocatorPathElt::PatternMatch>()) {
@@ -4723,6 +4726,15 @@ bool ConstraintSystem::repairFailures(
47234726 // mismatches within the same tuple type can be coalesced later.
47244727 auto index = elt.getAs <LocatorPathElt::TupleElement>()->getIndex ();
47254728 path.pop_back ();
4729+
4730+ // Drop the tuple type path elements too, but extract each tuple type first.
4731+ if (path.back ().is <LocatorPathElt::TupleType>()) {
4732+ rhs = path.back ().getAs <LocatorPathElt::TupleType>()->getType ();
4733+ path.pop_back ();
4734+ lhs = path.back ().getAs <LocatorPathElt::TupleType>()->getType ();
4735+ path.pop_back ();
4736+ }
4737+
47264738 auto *tupleLocator = getConstraintLocator (locator.getAnchor (), path);
47274739
47284740 // Let this fail if it's a contextual mismatch with sequence element types,
@@ -5225,9 +5237,15 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
52255237 }
52265238
52275239 case TypeKind::Tuple: {
5240+ // Add each tuple type to the locator before matching the element types.
5241+ // This is useful for diagnostics, because the error message can use the
5242+ // full tuple type for several element mismatches. Use the original types
5243+ // to preserve sugar such as typealiases.
5244+ auto tmpTupleLoc = locator.withPathElement (LocatorPathElt::TupleType (type1));
5245+ auto tupleLoc = tmpTupleLoc.withPathElement (LocatorPathElt::TupleType (type2));
52285246 auto result = matchTupleTypes (cast<TupleType>(desugar1),
52295247 cast<TupleType>(desugar2),
5230- kind, subflags, locator );
5248+ kind, subflags, tupleLoc );
52315249 if (result != SolutionKind::Error)
52325250 return result;
52335251
0 commit comments