@@ -3400,13 +3400,13 @@ bool ConstraintSystem::repairFailures(
34003400 auto *loc = getConstraintLocator (locator);
34013401 auto *anchor = getAsExpr (simplifyLocatorToAnchor (loc));
34023402 // In cases where we have an extension with @dynamicCallable or
3403- // callAsFunction on types that can be expressed as literal e.g. String,
3404- // Interger, etc. and the mismatches are let _: Int = "foo" let's prefer to
3405- // still produce a conversion mismatch diagnostic.
3403+ // callAsFunction on types that can be expressed by a literal ( e.g., String
3404+ // or Int) and the mismatches are of the form let _: Int = "foo" let's
3405+ // prefer to still produce a conversion mismatch diagnostic.
34063406 if (anchor && isa<LiteralExpr>(anchor))
34073407 return false ;
34083408
3409- // Let's attempt to see if the callable value can be explicit called to
3409+ // Let's attempt to see if the callable value can be explicitly called to
34103410 // produce the expected dstType with an ApplicableFnConstraint and record
34113411 // the fixes accordingly.
34123412 auto applyLoc = getConstraintLocator (
@@ -3744,11 +3744,14 @@ bool ConstraintSystem::repairFailures(
37443744
37453745 auto *loc = getConstraintLocator (locator);
37463746 if (getType (destExpr)->is <LValueType>() || result.isFailure ()) {
3747- // Let this asignment failure be diagnosed by the AllowTupleTypeMismatch
3747+ // Let this assignment failure be diagnosed by the AllowTupleTypeMismatch
37483748 // fix already recorded.
37493749 if (hasFixFor (loc, FixKind::AllowTupleTypeMismatch))
37503750 return true ;
37513751
3752+ if (repairByInsertingExplicitCallOnCallableValue (lhs, rhs))
3753+ return true ;
3754+
37523755 conversionsOrFixes.push_back (
37533756 IgnoreAssignmentDestinationType::create (*this , lhs, rhs, loc));
37543757 } else {
@@ -4019,6 +4022,9 @@ bool ConstraintSystem::repairFailures(
40194022 if (repairOutOfOrderArgumentsInBinaryFunction (*this , conversionsOrFixes,
40204023 loc))
40214024 return true ;
4025+
4026+ if (repairByInsertingExplicitCallOnCallableValue (lhs, rhs))
4027+ return true ;
40224028
40234029 conversionsOrFixes.push_back (
40244030 AllowArgumentMismatch::create (*this , lhs, rhs, loc));
@@ -4236,7 +4242,10 @@ bool ConstraintSystem::repairFailures(
42364242 // `lhs` - is an result type and `rhs` is a contextual type.
42374243 if (repairByConstructingRawRepresentableType (lhs, rhs))
42384244 break ;
4239-
4245+
4246+ if (repairByInsertingExplicitCallOnCallableValue (lhs, rhs))
4247+ return true ;
4248+
42404249 conversionsOrFixes.push_back (IgnoreContextualType::create (
42414250 *this , lhs, rhs, getConstraintLocator (locator)));
42424251 break ;
@@ -8956,8 +8965,9 @@ ConstraintSystem::simplifyApplicableFnConstraint(
89568965 if (type1.getPointer () == desugar2) {
89578966 if (!isOperator || !hasInOut ()) {
89588967 if (locator.isForImplicitCallOfCallableValue ()) {
8959- // This overload can be trivially called to produce a value of expected
8960- // type record the insert explicit call fix.
8968+ // This overload has no parameters and the result type is obviously
8969+ // equivalent to the expected type, so we can record a insert explicit
8970+ // call fix for it.
89618971 if (recordFix (InsertExplicitCall::createWithResult (
89628972 *this , func1->getResult (), getConstraintLocator (locator))))
89638973 return SolutionKind::Error;
@@ -9121,13 +9131,14 @@ ConstraintSystem::simplifyApplicableFnConstraint(
91219131 .isFailure ()) {
91229132 if (locator.isForImplicitCallOfCallableValue ()) {
91239133 // This means overload cannot be called to produce a value of the
9124- // expected type, so we fallback to record the actual mismatch.
9134+ // expected type, so we fall back to record the actual mismatch.
91259135 if (auto *fix = fixImplicitCallOfCallableValue (
91269136 *this , func1->getResult (), locator))
91279137 return recordFix (fix, /* impact=*/ 5 ) ? SolutionKind::Error
91289138 : SolutionKind::Solved;
91299139 }
91309140 return SolutionKind::Error;
9141+ }
91319142
91329143 if (unwrapCount == 0 ) {
91339144 if (locator.isForImplicitCallOfCallableValue ()) {
@@ -9138,7 +9149,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
91389149 return SolutionKind::Error;
91399150 }
91409151 return SolutionKind::Solved;
9141-
9152+ }
91429153 // Record any fixes we attempted to get to the correct solution.
91439154 auto *fix = ForceOptional::create (*this , origType2, func1,
91449155 getConstraintLocator (locator));
@@ -9416,7 +9427,7 @@ ConstraintSystem::simplifyDynamicCallableApplicableFnConstraint(
94169427 .isFailure ()) {
94179428 if (locator.isForImplicitCallOfCallableValue ()) {
94189429 // This dynamicCall overload cannot be called to produce a value of the
9419- // expected type, so we fallback to record the actual mismatch.
9430+ // expected type, so we fall back to record the actual mismatch.
94209431 if (auto *fix = fixImplicitCallOfCallableValue (
94219432 *this , func1->getResult (), locator))
94229433 return recordFix (fix, /* impact=*/ 5 ) ? SolutionKind::Error
0 commit comments