|
1 | 1 | // Test the -require-explicit-availability flag
|
2 | 2 | // REQUIRES: OS=macosx
|
3 | 3 |
|
4 |
| -// RUN: %swiftc_driver -typecheck -parse-stdlib -target x86_64-apple-macosx10.10 -Xfrontend -verify -require-explicit-availability -require-explicit-availability-target "macOS 10.10" %s |
5 |
| -// RUN: %swiftc_driver -typecheck -parse-stdlib -target x86_64-apple-macosx10.10 -warnings-as-errors %s |
| 4 | +// RUN: %swiftc_driver -typecheck -parse-as-library -target x86_64-apple-macosx10.10 -Xfrontend -verify -require-explicit-availability -require-explicit-availability-target "macOS 10.10" %s |
6 | 5 |
|
7 | 6 | public struct S { // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}}
|
8 | 7 | public func method() { }
|
@@ -91,3 +90,50 @@ public struct spiStruct {
|
91 | 90 | extension spiStruct {
|
92 | 91 | public func spiExtensionMethod() {}
|
93 | 92 | }
|
| 93 | + |
| 94 | +public var publicVar = S() // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}} |
| 95 | + |
| 96 | +@available(macOS 10.10, *) |
| 97 | +public var publicVarOk = S() |
| 98 | + |
| 99 | +public var (a, b) = (S(), S()) // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}} |
| 100 | + |
| 101 | +@available(macOS 10.10, *) |
| 102 | +public var (c, d) = (S(), S()) |
| 103 | + |
| 104 | +public var _ = S() // expected-error {{global variable declaration does not bind any variables}} |
| 105 | + |
| 106 | +public var implicitGet: S { // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}} |
| 107 | + return S() |
| 108 | +} |
| 109 | + |
| 110 | +@available(macOS 10.10, *) |
| 111 | +public var implicitGetOk: S { |
| 112 | + return S() |
| 113 | +} |
| 114 | + |
| 115 | +public var computed: S { // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}} |
| 116 | + get { return S() } |
| 117 | + set { } |
| 118 | +} |
| 119 | + |
| 120 | +public var computedHalf: S { // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}} |
| 121 | + @available(macOS 10.10, *) |
| 122 | + get { return S() } |
| 123 | + set { } |
| 124 | +} |
| 125 | + |
| 126 | +// FIXME the following warning is not needed. |
| 127 | +public var computedOk: S { // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}} |
| 128 | + @available(macOS 10.10, *) |
| 129 | + get { return S() } |
| 130 | + |
| 131 | + @available(macOS 10.10, *) |
| 132 | + set { } |
| 133 | +} |
| 134 | + |
| 135 | +@available(macOS 10.10, *) |
| 136 | +public var computedOk1: S { |
| 137 | + get { return S() } |
| 138 | + set { } |
| 139 | +} |
0 commit comments