|
1 |
| -// RUN: %target-swift-emit-sil -swift-version 4 -verify %s |
2 |
| -// RUN: %target-swift-emit-sil -swift-version 5 -verify %s |
| 1 | +// RUN: %target-swift-emit-sil -swift-version 4 -verify %s | %FileCheck %s |
| 2 | +// RUN: %target-swift-emit-sil -swift-version 5 -verify %s | %FileCheck %s |
3 | 3 |
|
4 | 4 | // Integration test to ensure that `type(of: self)` keeps working in
|
5 | 5 | // class convenience initializers, even though they are now implemented as
|
@@ -46,3 +46,63 @@ class C {
|
46 | 46 | self.init()
|
47 | 47 | }
|
48 | 48 | }
|
| 49 | + |
| 50 | +protocol P { |
| 51 | + static var n: Int { get } |
| 52 | + init(_: Int) |
| 53 | +} |
| 54 | + |
| 55 | +extension P { |
| 56 | + // FIXME: SILGen inserts an unnecessary copy when 'self' is |
| 57 | + // address-only. |
| 58 | + /* init(selfInit: ()) { |
| 59 | + self.init(type(of: self).n) |
| 60 | + } |
| 61 | + |
| 62 | + init(selfAssign: ()) { |
| 63 | + self = type(of: self).init(0) |
| 64 | + } */ |
| 65 | +} |
| 66 | + |
| 67 | +protocol PA : AnyObject { |
| 68 | + static var n: Int { get } |
| 69 | + init(_: Int) |
| 70 | +} |
| 71 | + |
| 72 | +extension PA { |
| 73 | + init(selfInit: ()) { |
| 74 | + // This is OK; we can get the type of 'self' from the self metatype |
| 75 | + // argument. |
| 76 | + self.init(type(of: self).n) |
| 77 | + } |
| 78 | + |
| 79 | + // FIXME: Not yet supported, but should be |
| 80 | + /* init(selfAssign: ()) { |
| 81 | + self = type(of: self).init(0) |
| 82 | + } */ |
| 83 | +} |
| 84 | + |
| 85 | +class CC { |
| 86 | + class var n: Int { 0 } |
| 87 | + required init(_: Int) {} |
| 88 | +} |
| 89 | + |
| 90 | +protocol PC : CC {} |
| 91 | + |
| 92 | +extension PC { |
| 93 | + // CHECK-LABEL: sil hidden @$s042definite_init_type_of_self_in_convenience_B02PCPAAE0E4Initxyt_tcfC : $@convention(method) <Self where Self : PC> (@thick Self.Type) -> @owned Self { |
| 94 | + init(selfInit: ()) { |
| 95 | + // This is OK; we can get the type of 'self' from the self metatype |
| 96 | + // argument. |
| 97 | + self.init(type(of: self).n) |
| 98 | + |
| 99 | + // CHECK: [[SELF:%.*]] = upcast %0 : $@thick Self.Type to $@thick CC.Type |
| 100 | + // CHECK: [[INIT:%.*]] = class_method [[SELF]] : $@thick CC.Type, #CC.init!allocator : (CC.Type) -> (Int) -> CC, $@convention(method) (Int, @thick CC.Type) -> @owned CC |
| 101 | + // CHECK: apply [[INIT]]({{.*}}, [[SELF]]) : $@convention(method) (Int, @thick CC.Type) -> @owned CC |
| 102 | + } |
| 103 | + |
| 104 | + // FIXME: Not yet supported, but should be |
| 105 | + /* init(selfAssign: ()) { |
| 106 | + self = type(of: self).init(0) |
| 107 | + } */ |
| 108 | +} |
0 commit comments