mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user