@@ -2797,6 +2797,20 @@ ConstraintSystem::TypeMatchResult
2797
2797
ConstraintSystem::matchTypes (Type type1, Type type2, ConstraintKind kind,
2798
2798
TypeMatchOptions flags,
2799
2799
ConstraintLocatorBuilder locator) {
2800
+
2801
+ if (!type1->isTypeVariableOrMember ()
2802
+ && !type2->isTypeVariableOrMember ()
2803
+ && type1->isEqual (type2)) {
2804
+ if (locator.getBaseLocator ()->
2805
+ isLastElement (ConstraintLocator::PathElementKind::ExplicityTypeCoercion)) {
2806
+ if (!hasFixFor (locator.getBaseLocator ())) {
2807
+ auto *fix = RemoveUnecessaryCoercion::create (*this , type2,
2808
+ locator.getBaseLocator ());
2809
+ recordFix (fix);
2810
+ }
2811
+ }
2812
+ }
2813
+
2800
2814
// If we have type variables that have been bound to fixed types, look through
2801
2815
// to the fixed type.
2802
2816
type1 = getFixedTypeRecursive (type1, flags, kind == ConstraintKind::Equal);
@@ -2806,15 +2820,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2806
2820
auto desugar2 = type2->getDesugaredType ();
2807
2821
2808
2822
// If the types are obviously equivalent, we're done.
2809
- if (desugar1->isEqual (desugar2)) {
2810
- if (locator.getBaseLocator ()->
2811
- isLastElement (ConstraintLocator::PathElementKind::ExplicityTypeCoercion)) {
2812
- auto *fix = RemoveUnecessaryCoercion::create (*this , type2,
2813
- locator.getBaseLocator ());
2814
- recordFix (fix);
2815
- }
2816
- if (!isa<InOutType>(desugar2))
2817
- return getTypeMatchSuccess ();
2823
+ if (desugar1->isEqual (desugar2)
2824
+ && !isa<InOutType>(desugar2)) {
2825
+ return getTypeMatchSuccess ();
2818
2826
}
2819
2827
2820
2828
// Local function that should be used to produce the return value whenever
@@ -7756,10 +7764,7 @@ void ConstraintSystem::addExplicitConversionConstraint(
7756
7764
auto coerceLocator = [&]() {
7757
7765
if (auto expr = dyn_cast_or_null<CoerceExpr>(locatorPtr->getAnchor ())) {
7758
7766
// Only adding this path for explicty coercions e.g _ = a as Int
7759
- // and for non literal/array-literal subExpr.
7760
- if (!expr->isImplicit ()
7761
- && !isa<LiteralExpr>(expr->getSubExpr ())
7762
- && !isa<CollectionExpr>(expr->getSubExpr ()))
7767
+ if (!expr->isImplicit ())
7763
7768
return getConstraintLocator (expr, LocatorPathElt::ExplicitTypeCoercion ());
7764
7769
}
7765
7770
return locatorPtr;
0 commit comments