@@ -3975,10 +3975,17 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
3975
3975
3976
3976
auto result = matchFunctionTypes (func1, func2, kind, flags, locator);
3977
3977
3978
- // If this is a type mismatch in assignment, we don't really care
3979
- // (yet) was it argument or result type mismatch, let's produce a
3980
- // diagnostic which means both function types.
3981
3978
if (shouldAttemptFixes () && result.isFailure ()) {
3979
+ // If this is a contextual type mismatch failure
3980
+ // let's give the solver a chance to "fix" it.
3981
+ if (auto last = locator.last ()) {
3982
+ if (last->is <LocatorPathElt::ContextualType>())
3983
+ break ;
3984
+ }
3985
+
3986
+ // If this is a type mismatch in assignment, we don't really care
3987
+ // (yet) was it argument or result type mismatch, let's produce a
3988
+ // diagnostic which mentions both function types.
3982
3989
auto *anchor = locator.getAnchor ();
3983
3990
if (anchor && isa<AssignExpr>(anchor))
3984
3991
break ;
@@ -8464,15 +8471,24 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
8464
8471
if (recordFix (fix))
8465
8472
return SolutionKind::Error;
8466
8473
8467
- // If type produced by expression is a function type
8468
- // with result type matching contextual, it should have
8469
- // been diagnosed as "missing explicit call", let's
8470
- // increase the score to make sure that we don't impede that.
8471
- if (auto *fnType = type1->getAs <FunctionType>()) {
8472
- auto result = matchTypes (fnType->getResult (), type2, matchKind,
8473
- TMF_ApplyingFix, locator);
8474
- if (result == SolutionKind::Solved)
8475
- increaseScore (SK_Fix);
8474
+ if (auto *fnType1 = type1->getAs <FunctionType>()) {
8475
+ // If this is a contextual mismatch between two
8476
+ // function types which we couldn't find a more
8477
+ // speficit fix for. Let's assume that such types
8478
+ // are competely disjoint and adjust impact of
8479
+ // the fix accordingly.
8480
+ if (auto *fnType2 = type2->getAs <FunctionType>()) {
8481
+ increaseScore (SK_Fix, 10 );
8482
+ } else {
8483
+ // If type produced by expression is a function type
8484
+ // with result type matching contextual, it should have
8485
+ // been diagnosed as "missing explicit call", let's
8486
+ // increase the score to make sure that we don't impede that.
8487
+ auto result = matchTypes (fnType1->getResult (), type2, matchKind,
8488
+ TMF_ApplyingFix, locator);
8489
+ if (result == SolutionKind::Solved)
8490
+ increaseScore (SK_Fix);
8491
+ }
8476
8492
}
8477
8493
8478
8494
return SolutionKind::Solved;
0 commit comments