Skip to content

Commit eebf2e2

Browse files
committed
[TypeChecker] NFC: Add some more tests for Double <-> CGFloat implicit conversion
1 parent 8c4a0dc commit eebf2e2

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

test/Misc/misc_diagnostics.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,32 @@ func test_implicit_cgfloat_conversion() {
183183
let cgf: CGFloat = 0.0
184184

185185
test_to(d) // Ok (Double -> CGFloat
186-
test_to(f) // error
186+
test_to(f) // expected-error {{cannot convert value of type 'Float' to expected argument type 'CGFloat'}}
187+
test_to(d + d) // Ok (Double -> CGFloat for both arguments)
188+
test_to(d + cgf) // Ok
189+
test_to(d + cgf - d) // Ok
190+
test_to(d + cgf - cgf) // Ok (only one choice here to conver `d` to CGFloat)
187191

188192
test_from(cgf) // Ok (CGFloat -> Double)
189-
test_from(f) // error
193+
test_from(f) // expected-error {{cannot convert value of type 'Float' to expected argument type 'Double'}}
194+
test_from(cgf + cgf) // Ok (CGFloat -> Double for both arguments)
195+
test_from(d + cgf) // Ok
196+
test_from(cgf + d - cgf) // Ok
197+
test_from(cgf + d - d) // Ok (only one choice here to conver `cgf` to Double)
198+
199+
func test_returns_double(_: CGFloat) -> Double {
200+
42.0
201+
}
202+
203+
func test_returns_cgfloat(_: Double) -> CGFloat {
204+
42.0
205+
}
206+
207+
test_to(test_returns_double(d)) // Ok (two implicit conversions here `d` -> CGFloat & result of `test_returns_double` to CGFloat)
208+
test_from(test_returns_cgfloat(cgf)) // Ok (same as above by in other direction)
190209

191210
let _: CGFloat = d // Ok
192-
let _: CGFloat = f // error
211+
let _: CGFloat = f // expected-error {{cannot convert value of type 'Float' to specified type 'CGFloat'}}
193212
let _: Double = cgf // Ok
194-
let _: Float = cgf // error
213+
let _: Float = cgf // expected-error {{cannot convert value of type 'CGFloat' to specified type 'Float'}}
195214
}

0 commit comments

Comments
 (0)