@@ -2530,7 +2530,27 @@ bool ConstraintSystem::repairFailures(
2530
2530
auto *fix = AllowTupleTypeMismatch::create (*this , lhs, rhs,
2531
2531
getConstraintLocator (locator));
2532
2532
conversionsOrFixes.push_back (fix);
2533
+ break ;
2533
2534
}
2535
+
2536
+ // If either side is not yet resolved, it's too early for this fix.
2537
+ if (lhs->isTypeVariableOrMember () || rhs->isTypeVariableOrMember ())
2538
+ break ;
2539
+
2540
+ // If contextual type is an existential value, it's handled
2541
+ // after conversion restriction is attempted.
2542
+ if (rhs->isExistentialType ())
2543
+ break ;
2544
+
2545
+ // TODO(diagnostics): This is a problem related to `inout` mismatch,
2546
+ // in argument position, and we got here from CSDiag. Once
2547
+ // argument-to-pararameter conversion failures are implemented,
2548
+ // this check could be removed.
2549
+ if (lhs->is <InOutType>() || rhs->is <InOutType>())
2550
+ break ;
2551
+
2552
+ conversionsOrFixes.push_back (IgnoreContextualType::create (
2553
+ *this , lhs, rhs, getConstraintLocator (locator)));
2534
2554
break ;
2535
2555
}
2536
2556
@@ -7103,7 +7123,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
7103
7123
case FixKind::RemoveAddressOf:
7104
7124
case FixKind::SkipSameTypeRequirement:
7105
7125
case FixKind::SkipSuperclassRequirement:
7106
- case FixKind::ContextualMismatch:
7107
7126
case FixKind::AddMissingArguments:
7108
7127
case FixKind::DefaultArgumentTypeMismatch:
7109
7128
case FixKind::SkipUnhandledConstructInFunctionBuilder:
@@ -7112,6 +7131,24 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
7112
7131
return recordFix (fix) ? SolutionKind::Error : SolutionKind::Solved;
7113
7132
}
7114
7133
7134
+ case FixKind::ContextualMismatch: {
7135
+ if (recordFix (fix))
7136
+ return SolutionKind::Error;
7137
+
7138
+ // If type produced by expression is a function type
7139
+ // with result type matching contextual, it should have
7140
+ // been diagnosed as "missing explicit call", let's
7141
+ // increase the score to make sure that we don't impede that.
7142
+ if (auto *fnType = type1->getAs <FunctionType>()) {
7143
+ auto result =
7144
+ matchTypes (fnType->getResult (), type2, matchKind, subflags, locator);
7145
+ if (result == SolutionKind::Solved)
7146
+ increaseScore (SK_Fix);
7147
+ }
7148
+
7149
+ return SolutionKind::Solved;
7150
+ }
7151
+
7115
7152
case FixKind::UseSubscriptOperator:
7116
7153
case FixKind::ExplicitlyEscaping:
7117
7154
case FixKind::CoerceToCheckedCast:
0 commit comments