|
8 | 8 | // REQUIRES: optimized_stdlib |
9 | 9 | // REQUIRES: swift_feature_Embedded |
10 | 10 |
|
11 | | -class MyClass { |
| 11 | +public class MyClass { |
12 | 12 | init() { print("MyClass.init") } |
13 | 13 | deinit { print("MyClass.deinit") } |
14 | 14 | func foo() { print("MyClass.foo") } |
15 | 15 | } |
16 | 16 |
|
17 | | -class MySubClass: MyClass { |
18 | | - var x = 27 |
| 17 | +public class MySubClass: MyClass { |
| 18 | + var x: Int |
| 19 | + |
| 20 | + override init() { |
| 21 | + self.x = 27 |
| 22 | + print("MySubClass.init") |
| 23 | + } |
| 24 | + |
| 25 | + public init(p: some P) { |
| 26 | + self.x = p.get() |
| 27 | + super.init() |
| 28 | + print("MySubClass.init") |
| 29 | + } |
19 | 30 |
|
20 | | - override init() { print("MySubClass.init") } |
21 | 31 | deinit { print("MySubClass.deinit") } |
22 | | - override func foo() { print("MySubClass.foo") } |
| 32 | + |
| 33 | + override func foo() { print("MySubClass.foo: \(x)") } |
23 | 34 |
|
24 | 35 | func printX() { |
25 | 36 | print(x) |
26 | 37 | } |
27 | 38 | } |
28 | 39 |
|
29 | | -class MySubSubClass: MySubClass { |
30 | | - override init() { print("MySubSubClass.init") } |
| 40 | +public protocol P { |
| 41 | + func get() -> Int |
| 42 | +} |
| 43 | + |
| 44 | +struct S: P { |
| 45 | + let i: Int |
| 46 | + |
| 47 | + func get() -> Int { i } |
| 48 | +} |
| 49 | + |
| 50 | +public class MySubSubClass: MySubClass { |
| 51 | + override init() { |
| 52 | + print("MySubSubClass.init") |
| 53 | + super.init() |
| 54 | + } |
| 55 | + |
31 | 56 | deinit { print("MySubSubClass.deinit") } |
| 57 | + |
32 | 58 | override func foo() { print("MySubSubClass.foo") } |
33 | 59 | } |
34 | 60 |
|
35 | | -class OtherSubClass: MyClass {} |
| 61 | +public class OtherSubClass: MyClass {} |
36 | 62 |
|
37 | 63 | func testCasting(_ title: StaticString, _ c: MyClass) { |
38 | 64 | print(title, terminator: "") |
@@ -81,10 +107,15 @@ struct Main { |
81 | 107 | o.1!.foo() |
82 | 108 | o.2!.foo() |
83 | 109 | // CHECK: MyClass.foo |
84 | | - // CHECK: MySubClass.foo |
| 110 | + // CHECK: MySubClass.foo: 27 |
85 | 111 | // CHECK: MySubSubClass.foo |
86 | 112 | print("") |
87 | 113 |
|
| 114 | + print("4b") // CHECK: 4b |
| 115 | + o.1 = MySubClass(p: S(i: 42)) |
| 116 | + o.1!.foo() |
| 117 | + // CHECK: MySubClass.foo: 42 |
| 118 | + |
88 | 119 | print("5") // CHECK: 5 |
89 | 120 | o.0 = nil |
90 | 121 | // CHECK: MyClass.deinit |
|
0 commit comments