Skip to content

Commit bc8d34f

Browse files
committed
[ConstraintSystem] Increase impact of implicit Double<->CGFloat associated with contextual type
Consider conversion with context to be worse by default because it means that expression as a whole couldn't get to the expected type. This also helps to disambiguate situations with multiple solutions where one of them has a contextual mismatch that requires implicit conversion and another produces correct contextual type but requires implicit conversion inside to get there.
1 parent ac6b717 commit bc8d34f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10545,6 +10545,14 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
1054510545
auto defaultImpact =
1054610546
restriction == ConversionRestrictionKind::CGFloatToDouble ? 1 : 2;
1054710547

10548+
// Consider conversion with context to be worse
10549+
// by default because it means that expression
10550+
// as a whole couldn't get to the expected type.
10551+
if (auto last = locator.last()) {
10552+
if (last->is<LocatorPathElt::ContextualType>())
10553+
++defaultImpact;
10554+
}
10555+
1054810556
auto numConversions = ImplicitValueConversions.size();
1054910557
increaseScore(SK_ImplicitValueConversion,
1055010558
defaultImpact * (numConversions + 1));

0 commit comments

Comments
 (0)