|
| 1 | +// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: swift_in_compiler |
| 4 | +// REQUIRES: executable_test |
| 5 | +// REQUIRES: optimized_stdlib |
| 6 | +// REQUIRES: OS=macosx || OS=linux-gnu |
| 7 | + |
| 8 | +public struct FooError: Error {} |
| 9 | + |
| 10 | +public class PrintingClass { |
| 11 | + init() { print("PrintingClass.init") } |
| 12 | + deinit { print("PrintingClass.deinit") } |
| 13 | +} |
| 14 | + |
| 15 | +public class Foo { |
| 16 | + var a: PrintingClass |
| 17 | + var b: PrintingClass |
| 18 | + init(shouldThrow: Bool) throws(FooError) { |
| 19 | + a = PrintingClass() |
| 20 | + if shouldThrow { throw FooError() } |
| 21 | + b = PrintingClass() |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +public class Bar: Foo { |
| 26 | + var value: Int = 17 |
| 27 | +} |
| 28 | + |
| 29 | +public class Wibble: Bar { |
| 30 | + var c: PrintingClass = .init() |
| 31 | +} |
| 32 | + |
| 33 | +_ = try? Wibble(shouldThrow: true) |
| 34 | +print("OK 1") |
| 35 | +// CHECK: PrintingClass.init |
| 36 | +// CHECK: PrintingClass.init |
| 37 | +// CHECK: PrintingClass.deinit |
| 38 | +// CHECK: PrintingClass.deinit |
| 39 | +// CHECK: OK 1 |
| 40 | + |
| 41 | +_ = try? Wibble(shouldThrow: false) |
| 42 | +print("OK 2") |
| 43 | +// CHECK: PrintingClass.init |
| 44 | +// CHECK: PrintingClass.init |
| 45 | +// CHECK: PrintingClass.init |
| 46 | +// CHECK: PrintingClass.deinit |
| 47 | +// CHECK: PrintingClass.deinit |
| 48 | +// CHECK: PrintingClass.deinit |
| 49 | +// CHECK: OK 2 |
| 50 | + |
| 51 | +public class Base { |
| 52 | + var baseMember: PrintingClass |
| 53 | + init(shouldThrow: Bool) throws(FooError) { |
| 54 | + if shouldThrow { throw FooError() } |
| 55 | + baseMember = PrintingClass() |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +class SubClass: Base { |
| 60 | + var subClassMember: PrintingClass = PrintingClass() |
| 61 | + override init(shouldThrow: Bool) throws(FooError) { |
| 62 | + try super.init(shouldThrow: shouldThrow) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +_ = try? SubClass(shouldThrow: true) |
| 67 | +print("OK 3") |
| 68 | +// CHECK: PrintingClass.init |
| 69 | +// CHECK: PrintingClass.deinit |
| 70 | +// CHECK: OK 3 |
| 71 | + |
| 72 | +_ = try? SubClass(shouldThrow: false) |
| 73 | +print("OK 4") |
| 74 | +// CHECK: PrintingClass.init |
| 75 | +// CHECK: PrintingClass.init |
| 76 | +// CHECK: PrintingClass.deinit |
| 77 | +// CHECK: PrintingClass.deinit |
| 78 | +// CHECK: OK 4 |
0 commit comments