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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
|
// RUN: %target-typecheck-verify-swift -parse-as-library \
// RUN: -define-availability "_myProject 2.0:macOS 12.0"
// REQUIRES: OS=macosx
// MARK: - Valid declarations
// Ok, top level functions
@backDeployed(before: macOS 12.0)
public func backDeployedTopLevelFunc() {}
// Ok, internal decls may be back deployed when @usableFromInline
@backDeployed(before: macOS 12.0)
@usableFromInline
internal func backDeployedUsableFromInlineTopLevelFunc() {}
// Ok, decls in a struct
public struct TopLevelStruct {
@backDeployed(before: macOS 12.0)
public init<T>(_ t: T) {}
@backDeployed(before: macOS 12.0)
public func backDeployedMethod() {}
@backDeployed(before: macOS 12.0)
public var backDeployedComputedProperty: Int { 98 }
@backDeployed(before: macOS 12.0)
public subscript(_ index: Int) -> Int { index }
@backDeployed(before: macOS 12.0)
public var readWriteProperty: Int {
get { 42 }
set(newValue) {}
}
@backDeployed(before: macOS 12.0)
public subscript(at index: Int) -> Int {
get { 42 }
set(newValue) {}
}
public var explicitReadAndModify: Int {
@backDeployed(before: macOS 12.0)
_read { yield 42 }
@backDeployed(before: macOS 12.0)
_modify {}
}
}
// Ok, decls in an enum
public enum TopLevelEnum {
case a, b
@backDeployed(before: macOS 12.0)
public init?(from name: String) {
switch name {
case "a": self = .a
case "b": self = .b
default: return nil
}
}
@backDeployed(before: macOS 12.0)
public func backDeployedMethod() {}
@backDeployed(before: macOS 12.0)
public var name: String {
switch self {
case .a: return "a"
case .b: return "b"
}
}
}
// Ok, final decls in a non-final class
public class TopLevelClass {
var x: Int
public init(x: Int) {
self.x = x
}
@backDeployed(before: macOS 12.0)
public convenience init() {
self.init(x: 1)
}
public func hook() {}
@backDeployed(before: macOS 12.0)
final public func backDeployedFinalMethod() {}
@backDeployed(before: macOS 12.0)
final public var backDeployedFinalComputedProperty: Int { 98 }
@backDeployed(before: macOS 12.0)
public static func backDeployedStaticMethod() {}
@backDeployed(before: macOS 12.0)
public final class func backDeployedClassMethod() {}
}
// Ok, final decls in a non-final, derived class
public class DerivedTopLevelClass: TopLevelClass {
@backDeployed(before: macOS 12.0)
final public func backDeployedFinalMethodOnDerived() {}
}
// Ok, decls in a final class
final public class FinalTopLevelClass {
var x: Int
public init(x: Int) {
self.x = x
}
@backDeployed(before: macOS 12.0)
public convenience init() {
self.init(x: 1)
}
@backDeployed(before: macOS 12.0)
public func backDeployedMethod() {}
@backDeployed(before: macOS 12.0)
public var backDeployedComputedProperty: Int { 98 }
}
// Ok, final decls in a non-final actor
@available(SwiftStdlib 5.1, *)
public actor TopLevelActor {
var x: Int
public init(x: Int) {
self.x = x
}
@backDeployed(before: macOS 12.0)
public init() {
self.init(x: 1)
}
@backDeployed(before: macOS 12.0)
final public func method() {}
@backDeployed(before: macOS 12.0)
final public var computedProperty: Int { 98 }
}
// Ok, decls on a final actor
@available(SwiftStdlib 5.1, *)
final public actor FinalTopLevelActor {
var x: Int
public init(x: Int) {
self.x = x
}
@backDeployed(before: macOS 12.0)
public init() {
self.init(x: 1)
}
@backDeployed(before: macOS 12.0)
public func method() {}
@backDeployed(before: macOS 12.0)
public var computedProperty: Int { 98 }
}
// Ok, decls in extensions of public types
extension TopLevelStruct {
@backDeployed(before: macOS 12.0)
public func backDeployedExtensionMethod() {}
}
extension TopLevelClass {
@backDeployed(before: macOS 12.0)
final public func backDeployedExtensionMethod() {}
}
extension FinalTopLevelClass {
@backDeployed(before: macOS 12.0)
public func backDeployedExtensionMethod() {}
}
@available(SwiftStdlib 5.1, *)
extension TopLevelActor {
@backDeployed(before: macOS 12.0)
final public func backDeployedExtensionMethod() {}
}
@available(SwiftStdlib 5.1, *)
extension FinalTopLevelActor {
@backDeployed(before: macOS 12.0)
public func backDeployedExtensionMethod() {}
}
public protocol TopLevelProtocol {}
extension TopLevelProtocol {
@backDeployed(before: macOS 12.0)
public func backDeployedExtensionMethod() {}
}
// MARK: - Unsupported declaration kinds
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
public class CannotBackDeployClass {}
public class CannotBackDeployClassDesignatedInit {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' cannot be applied to a non-final initializer}}
public init(x: Int) {}
}
public final class CannotBackDeployClassDeinit {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to deinitializer declarations}}
deinit {}
}
// Ok, final decls in a non-final, derived class
public class CannotBackDeployOverride: TopLevelClass {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' cannot be combined with 'override'}}
final public override func hook() {}
}
@available(SwiftStdlib 5.1, *)
public actor CannotBackDeployActorDesignatedInit {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' cannot be applied to a non-final initializer}}
public init(x: Int) {}
}
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
public struct CannotBackDeployStruct {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' must not be used on stored properties}}
public var cannotBackDeployStoredProperty: Int = 83
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' must not be used on stored properties}}
public lazy var cannotBackDeployLazyStoredProperty: Int = 15
}
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
public enum CannotBackDeployEnum {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
case cannotBackDeployEnumCase
}
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' must not be used on stored properties}}
public var cannotBackDeployTopLevelVar = 79
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
extension TopLevelStruct {}
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
protocol CannotBackDeployProtocol {}
@available(SwiftStdlib 5.1, *)
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' attribute cannot be applied to this declaration}}
public actor CannotBackDeployActor {}
public struct ConformsToTopLevelProtocol: TopLevelProtocol {
public init() {}
}
@available(SwiftStdlib 5.1, *)
@backDeployed(before: macOS 12.0) // expected-warning {{'@backDeployed' is unsupported on a var with a 'some' return type}}
public var cannotBackDeployVarWithOpaqueResultType: some TopLevelProtocol {
return ConformsToTopLevelProtocol()
}
@available(SwiftStdlib 5.1, *)
@backDeployed(before: macOS 12.0) // expected-warning {{'@backDeployed' is unsupported on a global function with a 'some' return type}}
public func cannotBackDeployFuncWithOpaqueResultType() -> some TopLevelProtocol {
return ConformsToTopLevelProtocol()
}
// MARK: - Function body diagnostics
public struct FunctionBodyDiagnostics {
public func publicFunc() {}
@usableFromInline func usableFromInlineFunc() {}
func internalFunc() {} // expected-note {{instance method 'internalFunc()' is not '@usableFromInline' or public}}
fileprivate func fileprivateFunc() {} // expected-note {{instance method 'fileprivateFunc()' is not '@usableFromInline' or public}}
private func privateFunc() {} // expected-note {{instance method 'privateFunc()' is not '@usableFromInline' or public}}
@backDeployed(before: macOS 12.0)
public func backDeployedMethod_macOS() {
struct Nested {} // expected-error {{type 'Nested' cannot be nested inside a '@backDeployed' function}}
publicFunc()
usableFromInlineFunc()
internalFunc() // expected-error {{instance method 'internalFunc()' is internal and cannot be referenced from a '@backDeployed' function}}
fileprivateFunc() // expected-error {{instance method 'fileprivateFunc()' is fileprivate and cannot be referenced from a '@backDeployed' function}}
privateFunc() // expected-error {{instance method 'privateFunc()' is private and cannot be referenced from a '@backDeployed' function}}
}
@backDeployed(before: iOS 13.0)
public func backDeployedMethod_iOS() {
#if !os(iOS)
// Since this function body is only back deployed on iOS, the statements
// of the body in a #if !os(iOS) block should be considered resilient.
struct Nested {}
publicFunc()
usableFromInlineFunc()
internalFunc()
fileprivateFunc()
privateFunc()
#endif
}
}
// MARK: - Incompatible declarations
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' may not be used on fileprivate declarations}}
fileprivate func filePrivateFunc() {}
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' may not be used on private declarations}}
private func privateFunc() {}
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' may not be used on internal declarations}}
internal func internalFunc() {}
private struct PrivateTopLevelStruct {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' may not be used on private declarations}}
public func effectivelyPrivateFunc() {}
}
public class TopLevelClass2 {
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' cannot be applied to a non-final instance method}}
public func nonFinalMethod() {}
@backDeployed(before: macOS 12.0) // expected-error {{'@backDeployed' cannot be applied to a non-final class method}}
public class func nonFinalClassMethod() {}
}
@backDeployed(before: macOS 12.0, macOS 13.0) // expected-error {{'@backDeployed' contains multiple versions for macOS}}
public func duplicatePlatformsFunc1() {}
@backDeployed(before: macOS 12.0)
@backDeployed(before: macOS 13.0) // expected-error {{'@backDeployed' contains multiple versions for macOS}}
public func duplicatePlatformsFunc2() {}
@backDeployed(before: macOS 12.0)
@_alwaysEmitIntoClient // expected-error {{'@_alwaysEmitIntoClient' cannot be applied to a back deployed global function}}
public func alwaysEmitIntoClientFunc() {}
@backDeployed(before: macOS 12.0)
@inlinable // Ok
public func inlinableFunc() {}
@backDeployed(before: macOS 12.0)
@_transparent // expected-error {{'@_transparent' cannot be applied to a back deployed global function}}
public func transparentFunc() {}
// MARK: - Attribute parsing
@backDeployed(before: macos 12.0, iOS 15.0) // expected-warning {{unknown platform 'macos' for attribute '@backDeployed'; did you mean 'macOS'?}} {{23-28=macOS}}
public func incorrectPlatformCaseFunc() {}
@backDeployed(before: mscos 12.0, iOS 15.0) // expected-warning {{unknown platform 'mscos' for attribute '@backDeployed'; did you mean 'macOS'?}} {{23-28=macOS}}
public func incorrectPlatformSimilarFunc() {}
@backDeployed(before: macOS 12.0, unknownOS 1.0) // expected-warning {{unknown platform 'unknownOS' for attribute '@backDeployed'}}
public func unknownOSFunc1() {}
@backDeployed(before: macOS 12.0)
@backDeployed(before: unknownOS 1.0) // expected-warning {{unknown platform 'unknownOS' for attribute '@backDeployed'}}
public func unknownOSFunc2() {}
@backDeployed(before: @) // expected-error {{expected platform in '@backDeployed' attribute}}
public func badPlatformFunc1() {}
@backDeployed(before: @ 12.0) // expected-error {{expected platform in '@backDeployed' attribute}}
public func badPlatformFunc2() {}
@backDeployed(before: macOS) // expected-error {{expected version number in '@backDeployed' attribute}}
public func missingVersionFunc1() {}
@backDeployed(before: macOS 12.0, iOS) // expected-error {{expected version number in '@backDeployed' attribute}}
public func missingVersionFunc2() {}
@backDeployed(before: macOS, iOS) // expected-error 2{{expected version number in '@backDeployed' attribute}}
public func missingVersionFunc3() {}
@backDeployed(before: macOS 0) // expected-warning {{expected version number in '@backDeployed' attribute; this is an error in the Swift 6 language mode}}
public func missingVersionFunc4() {}
@backDeployed(before: macOS 12.0, iOS 15.0,) // expected-error {{unexpected ',' separator}}
public func unexpectedSeparatorFunc() {}
@backDeployed(before: macOS 12.0.1) // expected-warning {{'@backDeployed' only uses major and minor version number}}
public func patchVersionFunc() {}
@backDeployed(before: macOS 12.0, * 9.0) // expected-warning {{* as platform name has no effect in '@backDeployed' attribute}}
public func wildcardWithVersionFunc() {}
@backDeployed(before: macOS 12.0, *) // expected-warning {{* as platform name has no effect in '@backDeployed' attribute}}
public func trailingWildcardFunc() {}
@backDeployed(before: macOS 12.0, *, iOS 15.0) // expected-warning {{* as platform name has no effect in '@backDeployed' attribute}}
public func embeddedWildcardFunc() {}
@backDeployed(before: _myProject 3.0) // expected-error {{reference to undefined version '3.0' for availability macro '_myProject'}}
public func macroVersioned() {}
@backDeployed(before: _myProject) // expected-error {{reference to undefined version '0' for availability macro '_myProject'}}
public func missingMacroVersion() {}
// Fall back to the default diagnostic when the macro is unknown.
@backDeployed(before: _unknownMacro) // expected-warning {{unknown platform '_unknownMacro' for attribute '@backDeployed'}}
// expected-error@-1 {{expected version number in '@backDeployed' attribute}}
public func unknownMacroMissingVersion() {}
@backDeployed(before: _unknownMacro 1.0) // expected-warning {{unknown platform '_unknownMacro' for attribute '@backDeployed'}}
public func unknownMacroVersioned() {}
@backDeployed(before: _unknownMacro 1.0, _myProject 2.0) // expected-warning {{unknown platform '_unknownMacro' for attribute '@backDeployed'}}
public func knownAndUnknownMacroVersioned() {}
@backDeployed() // expected-error {{expected 'before:' in '@backDeployed' attribute}}
// expected-error@-1 {{expected at least one platform version in '@backDeployed' attribute}}
public func emptyAttributeFunc() {}
@backDeployed(macOS 12.0) // expected-error {{expected 'before:' in '@backDeployed' attribute}} {{15-15=before:}}
public func missingBeforeFunc() {}
@backDeployed(before) // expected-error {{expected ':' after 'before' in '@backDeployed' attribute}} {{21-21=:}}
// expected-error@-1 {{expected at least one platform version in '@backDeployed' attribute}}
public func missingColonAfterBeforeFunc() {}
@backDeployed(before macOS 12.0) // expected-error {{expected ':' after 'before' in '@backDeployed' attribute}} {{21-21=:}}
public func missingColonBetweenBeforeAndPlatformFunc() {}
@backDeployed(before: macOS 12.0,) // expected-error {{unexpected ',' separator}} {{33-34=}}
public func unexpectedTrailingCommaFunc() {}
@backDeployed(before: macOS 12.0,, iOS 15.0) // expected-error {{unexpected ',' separator}} {{34-35=}}
public func extraCommaFunc() {}
@backDeployed(before:) // expected-error {{expected at least one platform version in '@backDeployed' attribute}}
public func emptyPlatformVersionsFunc() {}
@backDeployed // expected-error {{expected '(' in '@backDeployed' attribute}}
public func expectedLeftParenFunc() {}
@backDeployed(before: macOS 12.0 // expected-note {{to match this opening '('}}
public func expectedRightParenFunc() {} // expected-error {{expected ')' in '@backDeployed' argument list}}
// MARK: - Legacy attribute spelling
@_backDeploy(before: macOS 12.0)
public func legacyBackDeployFunc() {}
|