|
1 |
| -// Test the -require-explicit-availability flag |
2 |
| -// REQUIRES: OS=macosx |
3 |
| -// RUN: %empty-directory(%t) |
| 1 | +// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %s -require-explicit-availability=warn |
| 2 | +// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %s -library-level=api |
4 | 3 |
|
5 |
| -/// Using the flag directly raises warnings and fixits. |
6 |
| -// RUN: %swiftc_driver -typecheck -parse-as-library -Xfrontend -verify %s \ |
7 |
| -// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability \ |
8 |
| -// RUN: -require-explicit-availability-target "macOS 10.10" |
9 |
| -// RUN: %swiftc_driver -typecheck -parse-as-library -Xfrontend -verify %s \ |
10 |
| -// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability=warn \ |
11 |
| -// RUN: -require-explicit-availability-target "macOS 10.10" |
| 4 | +// This test should pass for all Apple platforms. |
| 5 | +// REQUIRES: VENDOR=apple |
12 | 6 |
|
13 |
| -/// Using -library-level api defaults to enabling warnings, without fixits. |
14 |
| -// RUN: sed -e "s/}} {{.*/}}/" < %s > %t/NoFixits.swift |
15 |
| -// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/NoFixits.swift \ |
16 |
| -// RUN: -target %target-cpu-apple-macosx10.10 -library-level api |
17 |
| - |
18 |
| -/// Explicitly disable the diagnostic. |
19 |
| -// RUN: sed -e 's/xpected-warning/not-something-expected/' < %s > %t/None.swift |
20 |
| -// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/None.swift \ |
21 |
| -// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability=ignore \ |
22 |
| -// RUN: -require-explicit-availability-target "macOS 10.10" -library-level api |
23 |
| - |
24 |
| -/// Upgrade the diagnostic to an error. |
25 |
| -// RUN: sed -e "s/xpected-warning/xpected-error/" < %s > %t/Errors.swift |
26 |
| -// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/Errors.swift \ |
27 |
| -// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability=error \ |
28 |
| -// RUN: -require-explicit-availability-target "macOS 10.10" |
29 |
| - |
30 |
| -/// Error on an invalid argument. |
31 |
| -// RUN: not %target-swift-frontend -typecheck %s -require-explicit-availability=NotIt 2>&1 \ |
32 |
| -// RUN: | %FileCheck %s --check-prefix CHECK-ARG |
33 |
| -// CHECK-ARG: error: unknown argument 'NotIt', passed to -require-explicit-availability, expected 'error', 'warn' or 'ignore' |
34 |
| - |
35 |
| -public struct S { // expected-warning {{public declarations should have an availability attribute with an introduction version}} |
| 7 | +public struct NoAvailabilityStruct { // expected-warning {{public declarations should have an availability attribute with an introduction version}} |
36 | 8 | public func method() { }
|
37 | 9 | }
|
38 | 10 |
|
39 |
| -@available(macOS, unavailable) |
| 11 | +@available(*, unavailable) |
40 | 12 | public struct UnavailableStruct {
|
41 | 13 | public func okMethod() { }
|
42 | 14 | }
|
43 | 15 |
|
44 |
| -public func foo() { bar() } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
45 |
| - |
46 |
| -@usableFromInline |
47 |
| -func bar() { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{-1:1-1=@available(macOS 10.10, *)\n}} |
48 |
| - |
49 |
| -@available(macOS 10.1, *) |
50 |
| -public func ok() { } |
51 |
| - |
52 |
| -@available(macOS, unavailable) |
53 |
| -public func unavailableOk() { } |
54 |
| - |
55 |
| -@available(macOS, deprecated: 10.10) |
56 |
| -public func missingIntro() { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{-1:1-1=@available(macOS 10.10, *)\n}} |
57 |
| - |
58 |
| -@available(iOS 9.0, *) |
59 |
| -public func missingTargetPlatform() { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{-1:1-1=@available(macOS 10.10, *)\n}} |
60 |
| - |
61 |
| -func privateFunc() { } |
62 |
| - |
63 |
| -@_alwaysEmitIntoClient |
64 |
| -public func alwaysEmitted() { } |
65 |
| - |
66 |
| -@available(macOS 10.1, *) |
67 |
| -struct SOk { |
68 |
| - public func okMethod() { } |
69 |
| -} |
70 |
| - |
71 |
| -precedencegroup MediumPrecedence {} |
72 |
| -infix operator + : MediumPrecedence |
73 |
| - |
74 |
| -public func +(lhs: S, rhs: S) -> S { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
75 |
| - |
76 |
| -public enum E { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
77 |
| - |
78 |
| -@available(macOS, unavailable) |
79 |
| -public enum UnavailableEnum { |
80 |
| - case caseOk |
81 |
| -} |
82 |
| - |
83 |
| -public class C { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
84 |
| - |
85 |
| -@available(macOS, unavailable) |
86 |
| -public class UnavailableClass { |
87 |
| - public func okMethod() { } |
88 |
| -} |
89 |
| - |
90 |
| -public protocol P { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
91 |
| - |
92 |
| -@available(macOS, unavailable) |
93 |
| -public protocol UnavailableProto { |
94 |
| - func requirementOk() |
95 |
| -} |
96 |
| - |
97 |
| -private protocol PrivateProto { } |
98 |
| - |
99 |
| -extension S { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
100 |
| - public func warnForPublicMembers() { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{3-3=@available(macOS 10.10, *)\n }} |
101 |
| -} |
102 |
| - |
103 |
| -@available(macOS 10.1, *) |
104 |
| -extension S { |
105 |
| - public func okWhenTheExtensionHasAttribute() { } |
106 |
| -} |
107 |
| - |
108 |
| -@available(macOS, unavailable) |
109 |
| -extension S { |
110 |
| - public func okWhenTheExtensionIsUnavailable() { } |
111 |
| -} |
112 |
| - |
113 |
| -extension S { |
114 |
| - internal func dontWarnWithoutPublicMembers() { } |
115 |
| - private func dontWarnWithoutPublicMembers1() { } |
116 |
| -} |
117 |
| - |
118 |
| -// An empty extension should be ok. |
119 |
| -extension S { } |
120 |
| - |
121 |
| -extension S : P { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
122 |
| -} |
123 |
| - |
124 |
| -extension S : PrivateProto { |
125 |
| -} |
126 |
| - |
127 |
| -open class OpenClass { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
128 |
| - |
129 |
| -private class PrivateClass { } |
130 |
| - |
131 |
| -extension PrivateClass { } |
132 |
| - |
133 |
| -@available(macOS 10.1, *) |
134 |
| -public protocol PublicProtocol { } |
135 |
| - |
136 |
| -@available(macOS 10.1, *) |
137 |
| -extension S : PublicProtocol { } |
138 |
| - |
139 |
| -@_spi(SPIsAreOK) |
140 |
| -public func spiFunc() { } |
141 |
| - |
142 |
| -@_spi(SPIsAreOK) |
143 |
| -public struct spiStruct { |
144 |
| - public func spiMethod() {} |
145 |
| -} |
146 |
| - |
147 |
| -extension spiStruct { |
148 |
| - public func spiExtensionMethod() {} |
149 |
| -} |
150 |
| - |
151 |
| -public var publicVar = S() // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
152 |
| - |
153 |
| -@available(macOS 10.10, *) |
154 |
| -public var publicVarOk = S() |
155 |
| - |
156 |
| -@available(macOS, unavailable) |
157 |
| -public var unavailablePublicVarOk = S() |
158 |
| - |
159 |
| -public var (a, b) = (S(), S()) // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
160 |
| - |
161 |
| -@available(macOS 10.10, *) |
162 |
| -public var (c, d) = (S(), S()) |
163 |
| - |
164 |
| -public var _ = S() // expected-error {{global variable declaration does not bind any variables}} |
165 |
| - |
166 |
| -public var implicitGet: S { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
167 |
| - return S() |
168 |
| -} |
169 |
| - |
170 |
| -@available(macOS 10.10, *) |
171 |
| -public var implicitGetOk: S { |
172 |
| - return S() |
173 |
| -} |
174 |
| - |
175 |
| -@available(macOS, unavailable) |
176 |
| -public var unavailableImplicitGetOk: S { |
177 |
| - return S() |
178 |
| -} |
179 |
| - |
180 |
| -public var computed: S { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
181 |
| - get { return S() } |
182 |
| - set { } |
183 |
| -} |
184 |
| - |
185 |
| -public var computedHalf: S { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
186 |
| - @available(macOS 10.10, *) |
187 |
| - get { return S() } |
188 |
| - set { } |
189 |
| -} |
190 |
| - |
191 |
| -// FIXME the following warning is not needed. |
192 |
| -public var computedOk: S { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
193 |
| - @available(macOS 10.10, *) |
194 |
| - get { return S() } |
195 |
| - |
196 |
| - @available(macOS 10.10, *) |
197 |
| - set { } |
198 |
| -} |
199 |
| - |
200 |
| -@available(macOS 10.10, *) |
201 |
| -public var computedOk1: S { |
202 |
| - get { return S() } |
203 |
| - set { } |
204 |
| -} |
205 |
| - |
206 |
| -public class SomeClass { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
207 |
| - public init () {} |
208 |
| - |
209 |
| - public subscript(index: String) -> Int { |
210 |
| - get { return 42; } |
211 |
| - set(newValue) { } |
212 |
| - } |
213 |
| -} |
214 |
| - |
215 |
| -extension SomeClass { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{1-1=@available(macOS 10.10, *)\n}} |
216 |
| - public convenience init(s : S) {} // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{3-3=@available(macOS 10.10, *)\n }} |
217 |
| - |
218 |
| - @available(macOS 10.10, *) |
219 |
| - public convenience init(s : SomeClass) {} |
220 |
| - |
221 |
| - public subscript(index: Int) -> Int { // expected-warning {{public declarations should have an availability attribute with an introduction version}} {{3-3=@available(macOS 10.10, *)\n }} |
222 |
| - get { return 42; } |
223 |
| - set(newValue) { } |
224 |
| - } |
225 |
| - |
226 |
| - @available(macOS 10.10, *) |
227 |
| - public subscript(index: S) -> Int { |
228 |
| - get { return 42; } |
229 |
| - set(newValue) { } |
230 |
| - } |
231 |
| -} |
232 |
| - |
233 |
| -@available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 13.0, macCatalyst 13.0, *) |
234 |
| -public struct StructWithImplicitMembers { } |
| 16 | +public func noAvailabilityFunc() { } // expected-warning {{public declarations should have an availability attribute with an introduction version}} |
235 | 17 |
|
236 |
| -extension StructWithImplicitMembers: Hashable { } |
237 |
| -// expected-note @-1 {{add @available attribute to enclosing extension}} |
238 |
| -// expected-warning @-2 {{public declarations should have an availability attribute with an introduction version}} |
239 |
| -// expected-error @-3 {{'StructWithImplicitMembers' is only available in macOS 10.15 or newer}} |
| 18 | +@available(macOS, introduced: 10.10) |
| 19 | +@available(iOS, introduced: 8) |
| 20 | +@available(watchOS, introduced: 2) |
| 21 | +@available(tvOS, introduced: 9) |
| 22 | +@available(visionOS, introduced: 1) |
| 23 | +public func hasAvailability() { } |
0 commit comments