Skip to content

Commit 6ed0c1e

Browse files
committed
[TypeChecker] NFC: Add more situations to Double <-> CGFloat tests
1 parent 6382e7b commit 6ed0c1e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

test/Misc/misc_diagnostics.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if let realRoomName = roomName as! NSString { // expected-warning{{forced cast f
1717

1818
var pi = 3.14159265358979
1919
var d: CGFloat = 2.0
20-
var dpi:CGFloat = d*pi // Ok (implicit conversion Float -> CGFloat)
20+
var dpi:CGFloat = d*pi // Ok (implicit conversion Double -> CGFloat)
2121

2222
let ff: CGFloat = floorf(20.0) // expected-error{{cannot convert value of type 'Float' to specified type 'CGFloat'}}
2323
let _: CGFloat = floor(20.0) // Ok (Double -> CGFloat) conversion
@@ -182,18 +182,18 @@ func test_implicit_cgfloat_conversion() {
182182
let f: Float = 0.0
183183
let cgf: CGFloat = 0.0
184184

185-
test_to(d) // Ok (Double -> CGFloat
185+
test_to(d) // Ok (Double -> CGFloat)
186186
test_to(f) // expected-error {{cannot convert value of type 'Float' to expected argument type 'CGFloat'}}
187187
test_to(d + d) // Ok (Double -> CGFloat for both arguments)
188188
test_to(d + cgf) // Ok
189-
test_to(d + cgf - d) // Ok
189+
test_to(d + cgf - d) // expected-error {{ambiguous use of operator '+'}} (Both Double and CGFloat are equaly viable here)
190190
test_to(d + cgf - cgf) // Ok (only one choice here to conver `d` to CGFloat)
191191

192192
test_from(cgf) // Ok (CGFloat -> Double)
193193
test_from(f) // expected-error {{cannot convert value of type 'Float' to expected argument type 'Double'}}
194194
test_from(cgf + cgf) // Ok (CGFloat -> Double for both arguments)
195195
test_from(d + cgf) // Ok
196-
test_from(cgf + d - cgf) // Ok
196+
test_from(cgf + d - cgf) // expected-error {{ambiguous use of operator '+'}} (Both Double and CGFloat are equaly viable here)
197197
test_from(cgf + d - d) // Ok (only one choice here to conver `cgf` to Double)
198198

199199
func test_returns_double(_: CGFloat) -> Double {
@@ -211,4 +211,13 @@ func test_implicit_cgfloat_conversion() {
211211
let _: CGFloat = f // expected-error {{cannot convert value of type 'Float' to specified type 'CGFloat'}}
212212
let _: Double = cgf // Ok
213213
let _: Float = cgf // expected-error {{cannot convert value of type 'CGFloat' to specified type 'Float'}}
214+
215+
// Let's make sure that implicit conversion doesn't interfere with optionality
216+
func test(a: CGFloat?) {
217+
let b = a ?? 0 // Produces non-optional binding of CGFloat type
218+
test_to(b) // Ok
219+
test_from(b) // Ok
220+
221+
let c: Double = (a ?? 0) as CGFloat // Ok with implicit conversion
222+
}
214223
}

0 commit comments

Comments
 (0)