|
| 1 | +// RUN: %target-swift-emit-sil -sil-verify-all -verify -enable-experimental-feature NoImplicitCopy %s |
| 2 | + |
| 3 | +// This testStruct specifically testStructs how DI and the move checkers interact with each other |
| 4 | + |
| 5 | +func testStructSimpleNoInit() { |
| 6 | + struct M: ~Copyable { |
| 7 | + private let i: Int // expected-note {{'self.i' not initialized}} |
| 8 | + |
| 9 | + // No initialization. Should get DI error and no crash. |
| 10 | + init() { |
| 11 | + } // expected-error {{return from initializer without initializing all stored properties}} |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +func testStructSimplePartialInit() { |
| 16 | + struct M: ~Copyable { |
| 17 | + private let i: Int |
| 18 | + private let i2: Int // expected-note {{'self.i2' not initialized}} |
| 19 | + |
| 20 | + init() { |
| 21 | + i = 5 |
| 22 | + } // expected-error {{return from initializer without initializing all stored properties}} |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func testStructSimplePartialInit2() { |
| 27 | + struct M: ~Copyable { |
| 28 | + private let i: Int = 5 |
| 29 | + private let i2: Int // expected-note {{'self.i2' not initialized}} |
| 30 | + |
| 31 | + init() { |
| 32 | + } // expected-error {{return from initializer without initializing all stored properties}} |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +func testStructGenericNoInit() { |
| 37 | + struct M<T>: ~Copyable { |
| 38 | + private let i: T // expected-note {{'self.i' not initialized}} |
| 39 | + |
| 40 | + init() { |
| 41 | + } // expected-error {{return from initializer without initializing all stored properties}} |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +func testStructGenericPartialInit() { |
| 46 | + struct M<T>: ~Copyable { |
| 47 | + private let i: T |
| 48 | + private let i2: T // expected-note {{'self.i2' not initialized}} |
| 49 | + |
| 50 | + init(_ t: T) { |
| 51 | + self.i = t |
| 52 | + } // expected-error {{return from initializer without initializing all stored properties}} |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +func testEnumNoInit() { |
| 57 | + enum E : ~Copyable { |
| 58 | + case first |
| 59 | + case second |
| 60 | + |
| 61 | + init() { |
| 62 | + } // expected-error {{'self.init' isn't called on all paths before returning from initializer}} |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func testEnumNoInitWithPayload() { |
| 67 | + @_moveOnly struct Empty {} |
| 68 | + |
| 69 | + enum E : ~Copyable { |
| 70 | + case first(Empty) |
| 71 | + case second |
| 72 | + |
| 73 | + init() { |
| 74 | + } // expected-error {{'self.init' isn't called on all paths before returning from initializer}} |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func testEnumNoInitWithGenericPayload() { |
| 79 | + @_moveOnly struct Empty {} |
| 80 | + |
| 81 | + enum E<T> : ~Copyable { |
| 82 | + case first(Empty) |
| 83 | + case second(T) |
| 84 | + |
| 85 | + init() { |
| 86 | + } // expected-error {{'self.init' isn't called on all paths before returning from initializer}} |
| 87 | + } |
| 88 | +} |
0 commit comments