@@ -337,19 +337,6 @@ func test_implicit_conversion_clash_with_partial_application_check() {
337
337
}
338
338
}
339
339
340
- // rdar://99352676
341
- // CHECK-LABEL: sil hidden [ossa] @$s34implicit_double_cgfloat_conversion20test_init_validationyyF : $@convention(thin) () -> () {
342
- func test_init_validation( ) {
343
- class Foo {
344
- static let bar = 100.0
345
-
346
- func getBar( ) -> CGFloat ? {
347
- return Self . bar
348
- // CHECK: function_ref @$s12CoreGraphics7CGFloatVyACSdcfC : $@convention(method) (Double, @thin CGFloat.Type) -> CGFloat
349
- }
350
- }
351
- }
352
-
353
340
func test_ternary_and_nil_coalescing( ) {
354
341
func test( _: Double ? ) { }
355
342
@@ -389,3 +376,31 @@ func test_cgfloat_operator_is_attempted_with_literal_arguments(v: CGFloat?) {
389
376
let ratio = v ?? ( 2.0 / 16.0 )
390
377
let _: CGFloat = ratio // Ok
391
378
}
379
+
380
+ // Make sure that optimizer doesn't favor CGFloat -> Double conversion
381
+ // in presence of CGFloat initializer, otherwise it could lead to ambiguities.
382
+ func test_explicit_cgfloat_use_avoids_ambiguity( v: Int ) {
383
+ func test( _: CGFloat ) -> CGFloat { 0 }
384
+ func test( _: Double ) -> Double { 0 }
385
+
386
+ func hasCGFloatElement< C: Collection > ( _: C ) where C. Element == CGFloat { }
387
+
388
+ let arr = [ test ( CGFloat ( v) ) ]
389
+ hasCGFloatElement ( arr) // Ok
390
+
391
+ var total = 0.0 // This is Double by default
392
+ total += test ( CGFloat ( v) ) + CGFloat( v) // Ok
393
+ }
394
+
395
+ // rdar://99352676
396
+ // CHECK-LABEL: sil private [ossa] @$s34implicit_double_cgfloat_conversion20test_init_validationyyF3FooL_C6getBar12CoreGraphics7CGFloatVSgyF : $@convention(method) (@guaranteed Foo) -> Optional<CGFloat>
397
+ func test_init_validation( ) {
398
+ class Foo {
399
+ static let bar = 100.0
400
+
401
+ func getBar( ) -> CGFloat ? {
402
+ return Self . bar
403
+ // CHECK: function_ref @$s12CoreGraphics7CGFloatVyACSdcfC : $@convention(method) (Double, @thin CGFloat.Type) -> CGFloat
404
+ }
405
+ }
406
+ }
0 commit comments