File tree 2 files changed +63
-1
lines changed
2 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -14672,13 +14672,26 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
14672
14672
case ConversionRestrictionKind::CGFloatToDouble: {
14673
14673
// Prefer CGFloat -> Double over other way araund.
14674
14674
auto impact =
14675
- restriction == ConversionRestrictionKind::CGFloatToDouble ? 1 : 10;
14675
+ restriction == ConversionRestrictionKind::CGFloatToDouble ? 2 : 10;
14676
14676
14677
14677
if (restriction == ConversionRestrictionKind::DoubleToCGFloat) {
14678
14678
if (auto *anchor = locator.trySimplifyToExpr()) {
14679
14679
if (auto depth = getExprDepth(anchor))
14680
14680
impact = (*depth + 1) * impact;
14681
14681
}
14682
+ } else if (locator.directlyAt<AssignExpr>() ||
14683
+ locator.endsWith<LocatorPathElt::ContextualType>()) {
14684
+ // Situations like:
14685
+ //
14686
+ // let _: Double = <<CGFloat>>
14687
+ // <var/property of type Double> = <<CGFloat>>
14688
+ //
14689
+ // Used to be supported due to an incorrect fix added in
14690
+ // diagnostic mode. Lower impact here means that right-hand
14691
+ // side of the assignment is allowed to maintain CGFloat
14692
+ // until the very end which minimizes the number of conversions
14693
+ // used and keeps literals as Double when possible.
14694
+ impact = 1;
14682
14695
}
14683
14696
14684
14697
increaseScore(SK_ImplicitValueConversion, locator, impact);
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift
2
+
3
+ // REQUIRES: objc_interop
4
+
5
+ // Note this cannot use a fake Foundation because it lacks required operator overloads
6
+
7
+ import Foundation
8
+ import CoreGraphics
9
+
10
+ do {
11
+ func test( a: CGFloat , b: CGFloat ) {
12
+ let _: Double = a + b + 1 // Ok
13
+ let _: Double = a + b + 1.0 // Ok
14
+
15
+ var test : Double
16
+
17
+ test = a + b + 1 // Ok
18
+ test = a + b + 1.0 // Ok
19
+
20
+ _ = test
21
+
22
+ let _ = a + b + 1 // Ok
23
+ let _ = a + b + 1.0 // Ok
24
+
25
+ let _: Double = 1 + 2 + 3 // Ok
26
+
27
+ test = 1 + 2 + 3 // Ok
28
+ }
29
+ }
30
+
31
+ func test( cond: Bool , a: CGFloat , b: CGFloat ) {
32
+ var test : Double
33
+
34
+ let width = a - b // CGFloat
35
+
36
+ if cond {
37
+ test = ( width - 10 ) / 2 // Ok
38
+ } else {
39
+ test = ( width - 20.0 ) / 3 // Ok
40
+ }
41
+
42
+ _ = test
43
+ }
44
+
45
+ func test_atan_ambiguity( points: ( CGPoint , CGPoint ) ) {
46
+ var test = 0.0
47
+ test = atan ( ( points. 1 . y - points. 0 . y) / ( points. 1 . x - points. 0 . x) ) // Ok
48
+ _ = test
49
+ }
You can’t perform that action at this time.
0 commit comments