@@ -2587,7 +2587,8 @@ bool ConstraintSystem::repairFailures(
2587
2587
});
2588
2588
};
2589
2589
2590
- if (path.empty ()) {
2590
+ if (path.empty () ||
2591
+ path.back ().getKind () == ConstraintLocator::ExplicitTypeCoercion) {
2591
2592
if (!anchor)
2592
2593
return false ;
2593
2594
@@ -3212,9 +3213,16 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
3212
3213
// let's defer it until later proper check.
3213
3214
if (!(desugar1->is <DependentMemberType>() &&
3214
3215
desugar2->is <DependentMemberType>())) {
3215
- // If the types are obviously equivalent, we're done.
3216
- if (desugar1->isEqual (desugar2) && !isa<InOutType>(desugar2)) {
3217
- return getTypeMatchSuccess ();
3216
+ if (desugar1->isEqual (desugar2)) {
3217
+ if (kind >= ConstraintKind::Conversion &&
3218
+ !flags.contains (TMF_ApplyingFix)) {
3219
+ if (RemoveUnnecessaryCoercion::attempt (*this , type1, type2,
3220
+ getConstraintLocator (locator))) {
3221
+ return getTypeMatchFailure (locator);
3222
+ }
3223
+ }
3224
+ if (!isa<InOutType>(desugar2))
3225
+ return getTypeMatchSuccess ();
3218
3226
}
3219
3227
}
3220
3228
@@ -7999,6 +8007,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
7999
8007
case FixKind::GenericArgumentsMismatch:
8000
8008
case FixKind::AllowMutatingMemberOnRValueBase:
8001
8009
case FixKind::AllowTupleSplatForSingleParameter:
8010
+ case FixKind::RemoveUnnecessaryCoercion:
8002
8011
llvm_unreachable (" handled elsewhere" );
8003
8012
}
8004
8013
@@ -8305,11 +8314,20 @@ void ConstraintSystem::addExplicitConversionConstraint(
8305
8314
SmallVector<Constraint *, 3 > constraints;
8306
8315
8307
8316
auto locatorPtr = getConstraintLocator (locator);
8317
+ ConstraintLocator *coerceLocator = locatorPtr;
8318
+
8319
+ if (allowFixes && shouldAttemptFixes ()) {
8320
+ auto *anchor = locator.getAnchor ();
8321
+ if (isa<CoerceExpr>(anchor) && !anchor->isImplicit ()) {
8322
+ coerceLocator =
8323
+ getConstraintLocator (anchor, LocatorPathElt::ExplicitTypeCoercion ());
8324
+ }
8325
+ }
8308
8326
8309
8327
// Coercion (the common case).
8310
8328
Constraint *coerceConstraint =
8311
8329
Constraint::create (*this , ConstraintKind::Conversion,
8312
- fromType, toType, locatorPtr );
8330
+ fromType, toType, coerceLocator );
8313
8331
coerceConstraint->setFavored ();
8314
8332
constraints.push_back (coerceConstraint);
8315
8333
0 commit comments