@@ -2812,14 +2812,15 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2812
2812
}
2813
2813
}
2814
2814
2815
+ // If we are trying to perform coercion to the same type emit a warning.
2815
2816
if (locator.getBaseLocator ()->isTypeCoercion ()) {
2816
- auto expr = dyn_cast<CoerceExpr>(locator.getBaseLocator ()->getAnchor ());
2817
- if (!shouldSuppressDiagnostics ()) {
2818
- // If we are trying to perform coercion to the same type emit a warning.
2819
- if (type1-> getCanonicalType ()-> isEqual ( type2-> getCanonicalType ())) {
2820
- TC. diagnose ( expr->getLoc (), diag::unecessary_same_type_coercion, type2)
2821
- . fixItRemove ( SourceRange ( expr->getLoc (),
2822
- expr-> getCastTypeLoc (). getSourceRange (). End ));
2817
+ if ( auto expr = dyn_cast<CoerceExpr>(locator.getBaseLocator ()->getAnchor ())) {
2818
+ if (!shouldSuppressDiagnostics ()) {
2819
+ if (type1-> getCanonicalType ()-> isEqual (type2-> getCanonicalType ())) {
2820
+ TC. diagnose (expr-> getLoc (), diag::unecessary_same_type_coercion, type2)
2821
+ . fixItRemove ( SourceRange ( expr->getLoc (),
2822
+ expr->getCastTypeLoc (). getSourceRange (). End ));
2823
+ }
2823
2824
}
2824
2825
}
2825
2826
}
@@ -7521,9 +7522,12 @@ void ConstraintSystem::addExplicitConversionConstraint(
7521
7522
auto locatorPtr = getConstraintLocator (locator);
7522
7523
7523
7524
// Coercion (the common case).
7525
+ auto coercionPath = LocatorPathElt (ConstraintLocator::TypeCoercion);
7526
+ auto coerceLocator = getConstraintLocator (locator.getBaseLocator (),
7527
+ coercionPath);
7524
7528
Constraint *coerceConstraint =
7525
7529
Constraint::create (*this , ConstraintKind::Conversion,
7526
- fromType, toType, locatorPtr );
7530
+ fromType, toType, coerceLocator );
7527
7531
coerceConstraint->setFavored ();
7528
7532
constraints.push_back (coerceConstraint);
7529
7533
0 commit comments