mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ConstraintSystem] Adjust impact of implicit Double <-> CGFloat conversions
- Prefer CGFloat -> Double over the other way around to avoid ambiguities; - Every new conversion impacts the score by factor of number of previously applied conversions to make it possible to select solutions that require the least such conversions. - Prefer concrete overloads with Double <-> CGFloat conversion over generic ones.
This commit is contained in:
@@ -10527,7 +10527,14 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
|
||||
|
||||
case ConversionRestrictionKind::DoubleToCGFloat:
|
||||
case ConversionRestrictionKind::CGFloatToDouble: {
|
||||
increaseScore(SK_ImplicitValueConversion);
|
||||
// Prefer CGFloat -> Double over other way araund.
|
||||
auto defaultImpact =
|
||||
restriction == ConversionRestrictionKind::CGFloatToDouble ? 1 : 2;
|
||||
|
||||
auto numConversions = CurrentScore.Data[SK_ImplicitValueConversion];
|
||||
increaseScore(SK_ImplicitValueConversion,
|
||||
defaultImpact * (numConversions + 1));
|
||||
|
||||
if (worseThanBestSolution())
|
||||
return SolutionKind::Error;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user