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
|
// RUN: %swift -typecheck -verify -parse-stdlib -target x86_64-apple-ios51.0-macabi %s
// REQUIRES: maccatalyst_support
@available(macCatalyst, introduced: 1.0, deprecated: 2.0, obsoleted: 9.0,
message: "you don't want to do that anyway")
func obsoletedOnMacCatalyst() { }
// expected-note @-1{{'obsoletedOnMacCatalyst()' was obsoleted in Mac Catalyst 9.0}}
obsoletedOnMacCatalyst() // expected-error{{'obsoletedOnMacCatalyst()' is unavailable in Mac Catalyst: you don't want to do that anyway}}
@available(iOS, introduced: 1.0, deprecated: 2.0, obsoleted: 9.0,
message: "you don't want to do that anyway")
func obsoletedOnIOS() { }
// expected-note @-1{{'obsoletedOnIOS()' was obsoleted in iOS 9.0}}
obsoletedOnIOS() // expected-error{{'obsoletedOnIOS()' is unavailable in iOS: you don't want to do that anyway}}
@available(iOS, introduced: 1.0)
@available(macCatalyst, introduced: 1.0, obsoleted: 12.0)
func obsoletedOnMacCatalystButNotIOS() { }
// expected-note @-1{{'obsoletedOnMacCatalystButNotIOS()' was obsoleted in Mac Catalyst 12.0}}
obsoletedOnMacCatalystButNotIOS() // expected-error {{'obsoletedOnMacCatalystButNotIOS()' is unavailable}}
@available(iOS, introduced: 12.0, obsoleted: 12.0)
@available(macCatalyst, introduced: 12.0)
func obsoletedOnIOSButNotMacCatalyst() { }
obsoletedOnIOSButNotMacCatalyst() // no-error
@available(iOS, introduced: 1.0)
@available(macCatalyst, introduced: 1.0, deprecated: 12.0)
func deprecatedOnMacCatalystButNotIOS() { }
deprecatedOnMacCatalystButNotIOS() // expected-warning {{deprecatedOnMacCatalystButNotIOS()' was deprecated in Mac Catalyst 12.0}}
@available(iOS, introduced: 12.0, deprecated: 13.0)
@available(macCatalyst, introduced: 12.0)
func deprecatedOnIOSButNotMacCatalyst() { }
deprecatedOnIOSButNotMacCatalyst() // no-warning
@available(iOS 55.0, macCatalyst 56.0, *)
func introducedLaterOnMacCatalyst() {
}
@available(iOS 57.0, macCatalyst 56.0, *)
func introducedLaterOnIOS() {
}
// expected-note@+1 *{{add @available attribute to enclosing global function}}
func testPoundAvailable() {
if #available(macCatalyst 55.0, *) {
introducedLaterOnMacCatalyst() // expected-error {{'introducedLaterOnMacCatalyst()' is only available in Mac Catalyst 56.0 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
introducedLaterOnIOS() // expected-error {{'introducedLaterOnIOS()' is only available in Mac Catalyst 56.0 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
}
// macCatalyst should win over iOS when present
if #available(iOS 56.0, macCatalyst 55.0, *) {
introducedLaterOnMacCatalyst() // expected-error {{'introducedLaterOnMacCatalyst()' is only available in Mac Catalyst 56.0 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
introducedLaterOnIOS() // expected-error {{'introducedLaterOnIOS()' is only available in Mac Catalyst 56.0 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
}
if #available(iOS 55.0, macCatalyst 56.0, *) {
introducedLaterOnMacCatalyst() // no-warning
introducedLaterOnIOS() // no-error
}
if #available(iOS 57.0, macCatalyst 56.0, *) {
introducedLaterOnMacCatalyst() // no-warning
introducedLaterOnIOS() // no-error
}
// iOS availability should be inherited when macCatalyst is not present
if #available(iOS 55.0, *) {
introducedLaterOnMacCatalyst() // expected-error {{'introducedLaterOnMacCatalyst()' is only available in Mac Catalyst 56.0 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
introducedLaterOnIOS() // expected-error {{'introducedLaterOnIOS()' is only available in Mac Catalyst 56.0 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
}
if #available(iOS 56.0, *) {
introducedLaterOnMacCatalyst() // no-warning
introducedLaterOnIOS() // no-error
}
// macOS availability doesn't count on macCatalyst for Swift.
if #available(macOS 9999.0, *) {
introducedLaterOnMacCatalyst() // expected-error {{'introducedLaterOnMacCatalyst()' is only available in Mac Catalyst 56.0 or newer}}
// expected-note@-1 {{add 'if #available' version check}}
}
}
@available(iOS 55.0, *)
func testUnnecessaryPoundAvailable() { // expected-note*{{enclosing scope here}}
// Even though we're compiling for macCatalyst, the #available is expressed in terms of
// 'iOS', so we should use that to report to the user in the diagnostic.
if #available(iOS 54.0, *) {
// expected-warning@-1 {{unnecessary check for 'iOS'; enclosing scope ensures guard will always be true}}
}
if #available(macCatalyst 54.0, *) {
// expected-warning@-1 {{unnecessary check for 'macCatalyst'; enclosing scope ensures guard will always be true}}
}
if #available(macCatalyst 54.0, iOS 53.0, *) {
// expected-warning@-1 {{unnecessary check for 'macCatalyst'; enclosing scope ensures guard will always be true}}
}
if #available(iOS 53.0, macCatalyst 54.0, *) {
// expected-warning@-1 {{unnecessary check for 'macCatalyst'; enclosing scope ensures guard will always be true}}
}
}
// Test that we don't accidentally try to validate @available(iOS, ...) attrs
// on accessors against the property's @available(macCatalyst, ...) attr.
// (rdar://problem/50067784)
class X {
@available(iOS 3.2, macCatalyst 13, *)
var x: X {
get { return self }
set { }
}
}
protocol P: Builtin.AnyObject {
var x: X { get set }
}
extension X: P {}
// Test platform inheritance for iOS unavailability.
// rdar://68597591
@available(iOS, unavailable)
public struct UnavailableOniOS { } // expected-note 2 {{'UnavailableOniOS' has been explicitly marked unavailable here}}
@available(iOS, unavailable)
func unavailableOniOS(_ p: UnavailableOniOS) { } // ok
func functionUsingAnUnavailableType(_ p: UnavailableOniOS) { } // expected-error {{'UnavailableOniOS' is unavailable in iOS}}
public extension UnavailableOniOS { } // expected-error {{'UnavailableOniOS' is unavailable in iOS}}
@available(iOS, unavailable)
public extension UnavailableOniOS { // ok
func someMethod(_ p: UnavailableOniOS) { }
}
@available(iOS, unavailable)
@available(macCatalyst, introduced: 13.0)
public struct AvailableOnMacCatalyst { }
public extension AvailableOnMacCatalyst { } // ok
|