[ConstraintSystem] Allow attempting generic unary operators in presence of Double<->CGFloat conversion

Not all of the unary operators have `CGFloat` overloads,
so in order to preserve previous behavior (and overall
best solution) with implicit Double<->CGFloat conversion
we need to allow  attempting generic operators for such cases.

```swift
let _: CGFloat = -.pi / 2
```

`-` doesn't have `CGFloat` overload (which might be an oversight),
so in order to preserve type-checking behavior solver can't be
allowed to pick `-(Double) -> Double` based on overload of `/`,
the best possible solution would be with `/` as `(CGFloat, CGFloat) -> CGFloat`
and `-` on a `FloatingPoint` protocol.
This commit is contained in:
Pavel Yaskevich
2021-01-17 11:41:39 -08:00
parent cf8005b765
commit cd3ec8c508
3 changed files with 23 additions and 3 deletions

View File

@@ -696,8 +696,18 @@ bool DisjunctionStep::shouldSkip(const DisjunctionChoice &choice) const {
// already have a solution involving non-generic operators,
// but continue looking for a better non-generic operator
// solution.
if (shouldSkipGenericOperators() && choice.isGenericOperator()) {
return skip("generic");
if (BestNonGenericScore && choice.isGenericOperator()) {
auto &score = BestNonGenericScore->Data;
// Not all of the unary operators have `CGFloat` overloads,
// so in order to preserve previous behavior (and overall
// best solution) with implicit Double<->CGFloat conversion
// we need to allow attempting generic operators for such cases.
if (score[SK_ImplicitValueConversion] > 0 && choice.isUnaryOperator())
return false;
if (shouldSkipGenericOperators())
return skip("generic");
}
return false;