@@ -2793,6 +2793,26 @@ bool ConstraintSystem::repairFailures(
2793
2793
return !conversionsOrFixes.empty ();
2794
2794
}
2795
2795
2796
+ static bool
2797
+ shouldDiagnoseUnecessaryExplicityCoercion (ConstraintSystem &CS,
2798
+ ConstraintKind kind,
2799
+ ConstraintLocatorBuilder locator) {
2800
+ auto locatorPtr = locator.getBaseLocator ();
2801
+ if (kind >= ConstraintKind::Conversion) {
2802
+ if (locator.last ().hasValue () &&
2803
+ locator.last ().getValue ().getKind ()
2804
+ == ConstraintLocator::PathElementKind::ExplicityTypeCoercion) {
2805
+
2806
+ return !llvm::any_of (CS.getFixes (), [&locatorPtr](const ConstraintFix *fix) -> bool {
2807
+ if (fix->getLocator () == locatorPtr)
2808
+ return true ;
2809
+ return fix->getLocator ()->getAnchor () == locatorPtr->getAnchor ();
2810
+ });
2811
+ }
2812
+ }
2813
+ return false ;
2814
+ }
2815
+
2796
2816
ConstraintSystem::TypeMatchResult
2797
2817
ConstraintSystem::matchTypes (Type type1, Type type2, ConstraintKind kind,
2798
2818
TypeMatchOptions flags,
@@ -2808,22 +2828,11 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2808
2828
// If the types are obviously equivalent, we're done.
2809
2829
if (desugar1->isEqual (desugar2)) {
2810
2830
auto locatorPtr = locator.getBaseLocator ();
2811
- if (kind >= ConstraintKind::Conversion) {
2812
- if (locator.last ().hasValue () &&
2813
- locator.last ().getValue ().getKind ()
2814
- == ConstraintLocator::PathElementKind::ExplicityTypeCoercion) {
2815
-
2816
- if (!llvm::any_of (getFixes (), [&locatorPtr](const ConstraintFix *fix) -> bool {
2817
- if (fix->getLocator () == locatorPtr)
2818
- return true ;
2819
- return fix->getLocator ()->getAnchor () == locatorPtr->getAnchor ();
2820
- })) {
2821
- auto *fix = RemoveUnecessaryCoercion::create (*this , type2,
2822
- locatorPtr);
2823
- recordFix (fix);
2824
- }
2825
- }
2826
-
2831
+ if (shouldDiagnoseUnecessaryExplicityCoercion (*this , kind, locator)) {
2832
+ auto *fix = RemoveUnecessaryCoercion::create (*this , type2,
2833
+ locatorPtr);
2834
+ recordFix (fix);
2835
+
2827
2836
}
2828
2837
if (!isa<InOutType>(desugar2))
2829
2838
return getTypeMatchSuccess ();
0 commit comments