|
| 1 | +// RUN: %target-swift-emit-silgen -enable-sil-ownership %s | %FileCheck %s |
| 2 | + |
| 3 | +func takesOptionalFunction(_: (() -> ())?) {} |
| 4 | + |
| 5 | +struct CustomNull : ExpressibleByNilLiteral { |
| 6 | + init(nilLiteral: ()) {} |
| 7 | +} |
| 8 | + |
| 9 | +func takesANull(_: CustomNull) {} |
| 10 | + |
| 11 | +// CHECK-LABEL: sil hidden @$S8literals4testyyF : $@convention(thin) () -> () |
| 12 | +func test() { |
| 13 | + // CHECK: [[NIL:%.*]] = enum $Optional<@callee_guaranteed () -> ()>, #Optional.none!enumelt |
| 14 | + // CHECK: [[FN:%.*]] = function_ref @$S8literals21takesOptionalFunctionyyyycSgF |
| 15 | + // CHECK: apply [[FN]]([[NIL]]) |
| 16 | + _ = takesOptionalFunction(nil) |
| 17 | + |
| 18 | + // CHECK: [[METATYPE:%.*]] = metatype $@thin CustomNull.Type |
| 19 | + // CHECK: [[NIL_FN:%.*]] = function_ref @$S8literals10CustomNullV10nilLiteralACyt_tcfC |
| 20 | + // CHECK: [[NIL:%.*]] = apply [[NIL_FN]]([[METATYPE]]) |
| 21 | + // CHECK: [[FN:%.*]] = function_ref @$S8literals10takesANullyyAA10CustomNullVF |
| 22 | + // CHECK: apply [[FN]]([[NIL]]) |
| 23 | + _ = takesANull(nil) |
| 24 | +} |
| 25 | + |
| 26 | +class CustomStringClass : ExpressibleByStringLiteral { |
| 27 | + required init(stringLiteral value: String) {} |
| 28 | + required init(extendedGraphemeClusterLiteral value: String) {} |
| 29 | + required init(unicodeScalarLiteral value: String) {} |
| 30 | +} |
| 31 | + |
| 32 | +class CustomStringSubclass : CustomStringClass {} |
| 33 | + |
| 34 | +// CHECK-LABEL: sil hidden @$S8literals27returnsCustomStringSubclassAA0cdE0CyF : $@convention(thin) () -> @owned CustomStringSubclass |
| 35 | +// CHECK: [[METATYPE:%.*]] = metatype $@thick CustomStringSubclass.Type |
| 36 | +// CHECK: [[UPCAST:%.*]] = upcast [[METATYPE]] : $@thick CustomStringSubclass.Type to $@thick CustomStringClass.Type |
| 37 | +// CHECK: [[CTOR:%.*]] = class_method [[UPCAST]] : $@thick CustomStringClass.Type, #CustomStringClass.init!allocator.1 : (CustomStringClass.Type) -> (String) -> CustomStringClass, $@convention(method) (@owned String, @thick CustomStringClass.Type) -> @owned CustomStringClass |
| 38 | +// CHECK: [[RESULT:%.*]] = apply [[CTOR]]({{%.*}}, [[UPCAST]]) |
| 39 | +// CHECK: [[DOWNCAST:%.*]] = unchecked_ref_cast [[RESULT]] : $CustomStringClass to $CustomStringSubclass |
| 40 | +// CHECK: return [[DOWNCAST]] |
| 41 | +func returnsCustomStringSubclass() -> CustomStringSubclass { |
| 42 | + return "hello world" |
| 43 | +} |
0 commit comments