1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
// RUN: %swift -typecheck -verify -parse-stdlib -module-name Swift -target x86_64-apple-macosx10.10 %s
// Fake declarations of some standard library features for -parse-stdlib.
precedencegroup AssignmentPrecedence {}
enum Optional<T> {
case none
case some(T)
}
@available(OSX, introduced: 10.5, deprecated: 10.8, obsoleted: 10.9,
message: "you don't want to do that anyway")
func doSomething() { }
// expected-note @-1{{'doSomething()' was obsoleted in macOS 10.9}}
doSomething() // expected-error{{'doSomething()' is unavailable in macOS: you don't want to do that anyway}}
// Preservation of major.minor.micro
@available(OSX, introduced: 10.5, deprecated: 10.8, obsoleted: 10.9.1)
func doSomethingElse() { }
// expected-note @-1{{'doSomethingElse()' was obsoleted in macOS 10.9.1}}
doSomethingElse() // expected-error{{'doSomethingElse()' is unavailable in macOS}}
// Preservation of minor-only version
@available(OSX, introduced: 8.0, deprecated: 8.5, obsoleted: 10)
func doSomethingReallyOld() { }
// expected-note @-1{{'doSomethingReallyOld()' was obsoleted in macOS 10}}
doSomethingReallyOld() // expected-error{{'doSomethingReallyOld()' is unavailable in macOS}}
// Test deprecations in 10.10 and later
@available(OSX, introduced: 10.5, deprecated: 10.10,
message: "Use another function")
func deprecatedFunctionWithMessage() { }
deprecatedFunctionWithMessage() // expected-warning{{'deprecatedFunctionWithMessage()' was deprecated in macOS 10.10: Use another function}}
@available(OSX, introduced: 10.5, deprecated: 10.10)
func deprecatedFunctionWithoutMessage() { }
deprecatedFunctionWithoutMessage() // expected-warning{{'deprecatedFunctionWithoutMessage()' was deprecated in macOS 10.10}}
@available(OSX, introduced: 10.5, deprecated: 10.10,
message: "Use BetterClass instead")
class DeprecatedClass { }
func functionWithDeprecatedParameter(p: DeprecatedClass) { } // expected-warning{{'DeprecatedClass' was deprecated in macOS 10.10: Use BetterClass instead}}
@available(OSX, introduced: 10.5, deprecated: 10.11,
message: "Use BetterClass instead")
class DeprecatedClassIn10_11 { }
// Elements deprecated later than the minimum deployment target (which is 10.10, in this case) should not generate warnings
func functionWithDeprecatedLaterParameter(p: DeprecatedClassIn10_11) { }
// Unconditional platform unavailability
@available(OSX, unavailable)
func doSomethingNotOnOSX() { }
// expected-note @-1{{'doSomethingNotOnOSX()' has been explicitly marked unavailable here}}
doSomethingNotOnOSX() // expected-error{{'doSomethingNotOnOSX()' is unavailable in macOS}}
@available(iOS, unavailable)
func doSomethingNotOniOS() { }
doSomethingNotOniOS() // okay
// Unconditional platform deprecation
@available(OSX, deprecated)
func doSomethingDeprecatedOnOSX() { }
doSomethingDeprecatedOnOSX() // expected-warning{{'doSomethingDeprecatedOnOSX()' is deprecated in macOS}}
@available(iOS, deprecated)
func doSomethingDeprecatedOniOS() { }
doSomethingDeprecatedOniOS() // okay
@available(macOS 10.10, *)
struct TestStruct {} // expected-note 2 {{enclosing scope requires availability of macOS 10.10 or newer}}
@available(macOS 10.10, *)
extension TestStruct { // expected-note {{enclosing scope requires availability of macOS 10.10 or newer}}
@available(swift 400)
func doTheThing() {} // expected-note {{'doTheThing()' was introduced in Swift 400}}
@available(macOS 10.9, *) // expected-error {{instance method cannot be more available than enclosing scope}}
@available(swift 400)
func doAnotherThing() {} // expected-note {{'doAnotherThing()' was introduced in Swift 400}}
@available(macOS 10.12, *)
@available(swift 400)
func doThirdThing() {} // expected-note {{'doThirdThing()' was introduced in Swift 400}}
@available(macOS 10.12, *)
@available(swift 1)
func doFourthThing() {}
@available(*, deprecated)
func doDeprecatedThing() {}
}
extension TestStruct {
@available(macOS 10.9, *) // expected-warning {{instance method cannot be more available than enclosing scope}}
func doFifthThing() {}
struct NestedStruct {
@available(macOS 10.9, *) // expected-warning {{instance method cannot be more available than enclosing scope}}
func doSixthThing() {}
}
}
@available(macOS 10.11, *)
func testMemberAvailability() {
TestStruct().doTheThing() // expected-error {{'doTheThing()' is unavailable}}
TestStruct().doAnotherThing() // expected-error {{'doAnotherThing()' is unavailable}}
TestStruct().doThirdThing() // expected-error {{'doThirdThing()' is unavailable}}
TestStruct().doFourthThing() // expected-error {{'doFourthThing()' is only available in macOS 10.12 or newer}} expected-note {{'if #available'}}
TestStruct().doDeprecatedThing() // expected-warning {{'doDeprecatedThing()' is deprecated}}
}
extension TestStruct {
struct Data {
mutating func mutate() {}
}
var unavailableGetter: Data {
@available(macOS, unavailable, message: "bad getter")
get { return Data() } // expected-note 2 {{here}}
set {}
}
var unavailableSetter: Data {
get { return Data() }
@available(macOS, obsoleted: 10.5, message: "bad setter")
set {} // expected-note 2 {{setter for 'unavailableSetter' was obsoleted in macOS 10.5}}
}
}
func testAccessors() {
var t = TestStruct()
_ = t.unavailableGetter // expected-error {{getter for 'unavailableGetter' is unavailable in macOS}}
t.unavailableGetter = .init()
t.unavailableGetter.mutate() // expected-error {{getter for 'unavailableGetter' is unavailable in macOS}}
_ = t.unavailableSetter
t.unavailableSetter = .init() // expected-error {{setter for 'unavailableSetter' is unavailable in macOS: bad setter}}
t.unavailableSetter.mutate() // expected-error {{setter for 'unavailableSetter' is unavailable in macOS: bad setter}}
}
// Check available on extensions
@available(macOS, unavailable)
extension TestStruct {
func unavailInExtension() {} // expected-note 2 {{'unavailInExtension()' has been explicitly marked unavailable here}}
}
@available(macOS, obsoleted: 10.0)
extension TestStruct {
func obsoletedInExtension() {} // expected-note 2 {{'obsoletedInExtension()' was obsoleted in macOS 10.0}}
}
@available(macOS, deprecated: 10.0)
extension TestStruct {
func deprecatedInExtension() {}
}
@available(swift, introduced: 50.0)
extension TestStruct {
func introducedInExtensionSwift() {} // expected-note 2 {{'introducedInExtensionSwift()' was introduced in Swift 50.0}}
}
@available(macOS, introduced: 50)
extension TestStruct {
func introducedInExtensionMacOS() {}
}
TestStruct().unavailInExtension() // expected-error {{'unavailInExtension()' is unavailable in macOS}}
TestStruct().obsoletedInExtension() // expected-error {{'obsoletedInExtension()' is unavailable}}
TestStruct().deprecatedInExtension() // expected-warning {{'deprecatedInExtension()' was deprecated in macOS 10.0}}
TestStruct().introducedInExtensionSwift() // expected-error {{'introducedInExtensionSwift()' is unavailable}}
TestStruct().introducedInExtensionMacOS() // expected-error {{'introducedInExtensionMacOS()' is only available in macOS 50 or newer}}
// expected-note@-1{{add 'if #available' version check}}
extension TestStruct {
func availableFunc() {
unavailInExtension() // expected-error {{'unavailInExtension()' is unavailable in macOS}}
obsoletedInExtension() // expected-error {{'obsoletedInExtension()' is unavailable}}
deprecatedInExtension() // expected-warning {{'deprecatedInExtension()' was deprecated in macOS 10.0}}
introducedInExtensionSwift() // expected-error {{'introducedInExtensionSwift()' is unavailable}}
}
}
extension TestStruct { // expected-note{{add @available attribute to enclosing extension}}
func availableFuncMacOS() { // expected-note{{add @available attribute to enclosing instance method}}
introducedInExtensionMacOS() // expected-error {{'introducedInExtensionMacOS()' is only available in macOS 50 or newer}}
// expected-note@-1{{add 'if #available' version check}}
}
}
@available(macOS, introduced: 50)
extension TestStruct {
func futureFuncMacOS() {
introducedInExtensionMacOS()
}
}
@available(macOS, unavailable)
struct UnavailableStruct { }
@available(macOS, unavailable)
extension UnavailableStruct { } // no-error
#if os(macOS)
@available(macOS, unavailable)
extension UnavailableStruct { } // no-error
#endif
|