@@ -17,7 +17,7 @@ if let realRoomName = roomName as! NSString { // expected-warning{{forced cast f
17
17
18
18
var pi = 3.14159265358979
19
19
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)
21
21
22
22
let ff : CGFloat = floorf ( 20.0 ) // expected-error{{cannot convert value of type 'Float' to specified type 'CGFloat'}}
23
23
let _: CGFloat = floor ( 20.0 ) // Ok (Double -> CGFloat) conversion
@@ -182,18 +182,18 @@ func test_implicit_cgfloat_conversion() {
182
182
let f : Float = 0.0
183
183
let cgf : CGFloat = 0.0
184
184
185
- test_to ( d) // Ok (Double -> CGFloat
185
+ test_to ( d) // Ok (Double -> CGFloat)
186
186
test_to ( f) // expected-error {{cannot convert value of type 'Float' to expected argument type 'CGFloat'}}
187
187
test_to ( d + d) // Ok (Double -> CGFloat for both arguments)
188
188
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)
190
190
test_to ( d + cgf - cgf) // Ok (only one choice here to conver `d` to CGFloat)
191
191
192
192
test_from ( cgf) // Ok (CGFloat -> Double)
193
193
test_from ( f) // expected-error {{cannot convert value of type 'Float' to expected argument type 'Double'}}
194
194
test_from ( cgf + cgf) // Ok (CGFloat -> Double for both arguments)
195
195
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)
197
197
test_from ( cgf + d - d) // Ok (only one choice here to conver `cgf` to Double)
198
198
199
199
func test_returns_double( _: CGFloat ) -> Double {
@@ -211,4 +211,13 @@ func test_implicit_cgfloat_conversion() {
211
211
let _: CGFloat = f // expected-error {{cannot convert value of type 'Float' to specified type 'CGFloat'}}
212
212
let _: Double = cgf // Ok
213
213
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
+ }
214
223
}
0 commit comments