@@ -1598,23 +1598,24 @@ static ConstraintSystem::TypeMatchResult matchDeepTypeArguments(
1598
1598
ConstraintSystem &cs, ConstraintSystem::TypeMatchOptions subflags,
1599
1599
ArrayRef<Type> args1, ArrayRef<Type> args2,
1600
1600
ConstraintLocatorBuilder locator,
1601
- llvm::function_ref<bool (unsigned )> recordMismatch = [](unsigned ) { return false ; }) {
1601
+ llvm::function_ref<void (unsigned )> recordMismatch = [](unsigned ) {}) {
1602
1602
if (args1.size () != args2.size ()) {
1603
1603
return cs.getTypeMatchFailure (locator);
1604
1604
}
1605
1605
1606
+ auto allMatch = cs.getTypeMatchSuccess ();
1606
1607
for (unsigned i = 0 , n = args1.size (); i != n; ++i) {
1607
1608
auto result = cs.matchTypes (
1608
1609
args1[i], args2[i], ConstraintKind::Bind, subflags,
1609
1610
locator.withPathElement (LocatorPathElt::getGenericArgument (i)));
1610
1611
1611
1612
if (result.isFailure ()) {
1612
- if (!cs. shouldAttemptFixes () || ! recordMismatch (i))
1613
- return result;
1613
+ recordMismatch (i);
1614
+ allMatch = result;
1614
1615
}
1615
1616
}
1616
1617
1617
- return cs. getTypeMatchSuccess () ;
1618
+ return allMatch ;
1618
1619
}
1619
1620
1620
1621
ConstraintSystem::TypeMatchResult
@@ -1670,46 +1671,48 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
1670
1671
return result;
1671
1672
}
1672
1673
1673
- bool forRequirement = false ;
1674
- if (auto last = locator.last ()) {
1675
- forRequirement =
1676
- last->isTypeParameterRequirement () || last->isConditionalRequirement ();
1677
- }
1678
- // Optionals and arrays have a lot of special diagnostics and only one
1679
- // generic argument so if we' re dealing with one, don't produce generic
1680
- // arguments mismatch fixes.
1681
- // TODO(diagnostics): Move Optional and Array diagnostics over to the
1682
- // new framework.
1683
- bool isOptional = bound1->getDecl ()->isOptionalDecl ();
1684
- bool isArray = isArrayType (bound1).hasValue ();
1685
-
1686
1674
auto args1 = bound1->getGenericArgs ();
1687
1675
auto args2 = bound2->getGenericArgs ();
1688
1676
1689
- SmallVector<unsigned , 4 > failedArguments;
1690
1677
// Match up the generic arguments, exactly.
1691
- auto result =
1692
- matchDeepTypeArguments (*this , subflags, args1, args2, locator,
1693
- [&](unsigned position) {
1694
- if (forRequirement || isOptional || isArray)
1695
- return false ;
1696
-
1697
- failedArguments.push_back (position);
1698
- return true ;
1699
- });
1700
- if (!failedArguments.empty ()) {
1701
- auto *fix = GenericArgumentsMismatch::create (
1702
- *this , bound1, bound2, failedArguments, getConstraintLocator (locator));
1703
- // Increase the solution's score for each mismtach this fixes.
1704
- for (unsigned i = 0 ; i < failedArguments.size (); ++i) {
1705
- increaseScore (SK_Fix);
1678
+
1679
+ if (shouldAttemptFixes ()) {
1680
+ bool forRequirement = false ;
1681
+ if (auto last = locator.last ()) {
1682
+ forRequirement = last->isTypeParameterRequirement () ||
1683
+ last->isConditionalRequirement ();
1706
1684
}
1707
1685
1686
+ // Optionals and arrays have a lot of special diagnostics and only one
1687
+ // generic argument so if we' re dealing with one, don't produce generic
1688
+ // arguments mismatch fixes.
1689
+ // TODO(diagnostics): Move Optional and Array diagnostics over to the
1690
+ // new framework.
1691
+ bool isOptional = bound1->getDecl ()->isOptionalDecl ();
1692
+ bool isArray = isArrayType (bound1).hasValue ();
1693
+
1694
+ if (forRequirement || isOptional || isArray)
1695
+ return matchDeepTypeArguments (*this , subflags, args1, args2, locator);
1696
+
1697
+ SmallVector<unsigned , 4 > mismatches;
1698
+ auto result = matchDeepTypeArguments (
1699
+ *this , subflags, args1, args2, locator,
1700
+ [&mismatches](unsigned position) { mismatches.push_back (position); });
1701
+
1702
+ if (mismatches.empty ())
1703
+ return result;
1704
+
1705
+ auto *fix = GenericArgumentsMismatch::create (
1706
+ *this , bound1, bound2, mismatches, getConstraintLocator (locator));
1707
+
1708
1708
if (!recordFix (fix)) {
1709
+ // Increase the solution's score for each mismtach this fixes.
1710
+ increaseScore (SK_Fix, mismatches.size ());
1709
1711
return getTypeMatchSuccess ();
1710
1712
}
1713
+ return result;
1711
1714
}
1712
- return result ;
1715
+ return matchDeepTypeArguments (* this , subflags, args1, args2, locator) ;
1713
1716
}
1714
1717
1715
1718
ConstraintSystem::TypeMatchResult
@@ -2150,12 +2153,12 @@ bool ConstraintSystem::repairFailures(
2150
2153
}
2151
2154
2152
2155
auto hasConversionOrRestriction = [&](ConversionRestrictionKind kind) {
2153
- return llvm::any_of (
2154
- conversionsOrFixes, [kind](const RestrictionOrFix correction) {
2155
- if (auto restriction = correction.getRestriction ())
2156
- return restriction == kind;
2157
- return false ;
2158
- });
2156
+ return llvm::any_of (conversionsOrFixes,
2157
+ [kind](const RestrictionOrFix correction) {
2158
+ if (auto restriction = correction.getRestriction ())
2159
+ return restriction == kind;
2160
+ return false ;
2161
+ });
2159
2162
};
2160
2163
2161
2164
auto &elt = path.back ();
0 commit comments