|
| 1 | +// RUN: %target-typecheck-verify-swift |
| 2 | + |
| 3 | +class Root { |
| 4 | + let x = 0 |
| 5 | + |
| 6 | + // expected-error@+1 {{'super' cannot be used outside of a class computed property, method, initializer, deinitializer, or subscript}} |
| 7 | + let testStoredRoot = super.x |
| 8 | + |
| 9 | + var testComputedRoot: Int { |
| 10 | + // expected-error@+1 {{'super' cannot be used in class 'Root' because it has no superclass}} |
| 11 | + let _ = super.x |
| 12 | + } |
| 13 | + |
| 14 | + init(root: Void) { |
| 15 | + // expected-error@+1 {{'super' cannot be used in class 'Root' because it has no superclass}} |
| 16 | + super.x |
| 17 | + // expected-error@+1 {{'super' cannot be used in class 'Root' because it has no superclass}} |
| 18 | + super.init() |
| 19 | + } |
| 20 | + |
| 21 | + func testMethodRoot( |
| 22 | + // expected-error@+1 {{'super' cannot be used in class 'Root' because it has no superclass}} |
| 23 | + _: Int = super.x |
| 24 | + ) { |
| 25 | + // expected-error@+1 {{'super' cannot be used in class 'Root' because it has no superclass}} |
| 26 | + super.testMethodRoot() |
| 27 | + } |
| 28 | + |
| 29 | + deinit { |
| 30 | + // expected-error@+1 {{'super' cannot be used in class 'Root' because it has no superclass}} |
| 31 | + super.x |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +extension Root { |
| 36 | + func testMethodRootExtension() { |
| 37 | + // expected-error@+1 {{'super' cannot be used in extension of class 'Root' because it has no superclass}} |
| 38 | + super.x |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +class Derived: Root { |
| 43 | + // expected-error@+1 {{'super' cannot be used outside of a class computed property, method, initializer, deinitializer, or subscript}} |
| 44 | + let testStoredDerived = super.x |
| 45 | + |
| 46 | + var testComputedDerived: Int { |
| 47 | + super.x |
| 48 | + } |
| 49 | + |
| 50 | + init(derived: Void) { |
| 51 | + let _ = super.x |
| 52 | + } |
| 53 | + |
| 54 | + func testMethodDerived(_: Int = super.x) -> Int { |
| 55 | + super.x |
| 56 | + } |
| 57 | + |
| 58 | + deinit { |
| 59 | + let _ = super.x |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +protocol P: Derived {} |
| 64 | +extension P { |
| 65 | + func test() { |
| 66 | + // expected-error@+1 {{'super' cannot be used in non-class type 'P'}} |
| 67 | + super.x |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +enum E { |
| 72 | + case a( |
| 73 | + // expected-error@+1 {{'super' cannot be used in non-class type 'E'}} |
| 74 | + _: Int = super.undef |
| 75 | + ) |
| 76 | + |
| 77 | + func test() { |
| 78 | + // expected-error@+1 {{'super' cannot be used in non-class type 'E'}} |
| 79 | + super.undef |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +struct S { |
| 84 | + // expected-error@+1 {{'super' cannot be used in non-class type 'S'}} |
| 85 | + let testStoredRoot = super.undef |
| 86 | + |
| 87 | + init() { |
| 88 | + // expected-error@+1 {{'super' cannot be used in non-class type 'S'}} |
| 89 | + super.init() |
| 90 | + } |
| 91 | + |
| 92 | + func test() { |
| 93 | + // expected-error@+1 {{'super' cannot be used in non-class type 'S'}} |
| 94 | + super.undef |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +func test() { |
| 99 | + // expected-error@+1 {{'super' cannot be used outside of a class computed property, method, initializer, deinitializer, or subscript}} |
| 100 | + super.undef |
| 101 | +} |
| 102 | + |
| 103 | +// expected-error@+1 {{'super' cannot be used outside of a class computed property, method, initializer, deinitializer, or subscript}} |
| 104 | +super.init() |
0 commit comments