Skip to content

Commit 911040a

Browse files
Abstract check to another function
1 parent 4b5be17 commit 911040a

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

lib/Sema/CSSimplify.cpp

+25-16
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,26 @@ bool ConstraintSystem::repairFailures(
27932793
return !conversionsOrFixes.empty();
27942794
}
27952795

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+
27962816
ConstraintSystem::TypeMatchResult
27972817
ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
27982818
TypeMatchOptions flags,
@@ -2808,22 +2828,11 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
28082828
// If the types are obviously equivalent, we're done.
28092829
if (desugar1->isEqual(desugar2)) {
28102830
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+
28272836
}
28282837
if (!isa<InOutType>(desugar2))
28292838
return getTypeMatchSuccess();

0 commit comments

Comments
 (0)