File: availability_define.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (120 lines) | stat: -rw-r--r-- 6,042 bytes parent folder | download
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
// RUN: %target-typecheck-verify-swift \
// RUN:   -define-availability "_iOS53Aligned:macOS 50.0, iOS 53.0" \
// RUN:   -define-availability "_iOS54Aligned:macOS 51.0, iOS 54.0" \
// RUN:   -define-availability "_iOS54:iOS 54.0" \
// RUN:   -define-availability "_macOS51_0:macOS 51.0" \
// RUN:   -define-availability "_myProject 1.0:macOS 51.0" \
// RUN:   -define-availability "_myProject 2.5:macOS 52.5"

// RUN: %target-typecheck-verify-swift \
// RUN:   -enable-experimental-feature AvailabilityMacro='_iOS53Aligned:macOS 50.0, iOS 53.0' \
// RUN:   -enable-experimental-feature AvailabilityMacro="_iOS54Aligned:macOS 51.0, iOS 54.0" \
// RUN:   -enable-experimental-feature AvailabilityMacro='_iOS54:iOS 54.0' \
// RUN:   -enable-experimental-feature AvailabilityMacro="_macOS51_0:macOS 51.0" \
// RUN:   -enable-experimental-feature AvailabilityMacro='_myProject 1.0:macOS 51.0' \
// RUN:   -enable-experimental-feature AvailabilityMacro="_myProject 2.5:macOS 52.5"

// REQUIRES: OS=macosx

@available(_iOS53Aligned, *)
public func onMacOS50() {}

@available(_iOS54Aligned, *)
public func onMacOS51_0() {}

@available(_iOS54, _macOS51_0, tvOS 54.0, *)
public func composed() {}

@available(_iOS53Aligned, *)
@available(macOS, deprecated: 50)
public func onMacOSDeprecated() {}

@available(_myProject, *) // expected-error {{expected declaration}}
// expected-error @-1 {{reference to undefined version '0' for availability macro '_myProject'}}
public func onMyProject() {}

@available(_myProject 1.0, *)
public func onMyProjectV1() {}

@available(_myProject 2.5, *)
public func onMyProjectV2_5() {}

@available(_myProject 3.0, *)// expected-error {{expected declaration}}
// expected-error @-1 {{reference to undefined version '3.0' for availability macro '_myProject'}}
public func onMyProjectV3() {}

@available(_myProject 3_0, *)// expected-error {{expected declaration}}
// expected-error @-1 {{expected version number}}
public func brokenVersion() {}

@available(_unknownMacro, *) // expected-error {{expected declaration}}
// expected-error @-1 {{expected 'available' option such as 'unavailable', 'introduced', 'deprecated', 'obsoleted', 'message', or 'renamed'}}
public func unknownMacro() {}

@available(_iOS54) // expected-error {{must handle potential future platforms with '*'}}
public func noOtherOSes() {}

@available(_iOS53Aligned, *)
func client() {
  onMacOS50()
  onMacOS51_0() // expected-error {{is only available in macOS 51.0 or newer}}
  // expected-note @-1 {{add 'if #available' version check}}
  onMacOSDeprecated()

  if #available(_iOS54Aligned, *) {
    onMacOS51_0()
  }

  if #unavailable(_iOS54Aligned) {
    onMacOS51_0() // expected-error {{is only available in macOS 51.0 or newer}}
    // expected-note @-1 {{add 'if #available' version check}}
  } else {
    onMacOS51_0()
  }

  if #available(_unknownMacro, *) { } // expected-error {{expected version number}}
}

public func doIt(_ closure: () -> ()) {
  closure()
}

@inlinable
public func forbidMacrosInInlinableCode() {
  if #available(_iOS54Aligned, *) { } // expected-error {{availability macro cannot be used in an '@inlinable' function}}
  if #available(_iOS54, _macOS51_0, *) { } // expected-error {{availability macro cannot be used in an '@inlinable' function}}
  if #available(iOS 54.0, _macOS51_0, tvOS 54.0, *) { } // expected-error {{availability macro cannot be used in an '@inlinable' function}}
  if #unavailable(_iOS54Aligned) { } // expected-error {{availability macro cannot be used in an '@inlinable' function}}
  if #unavailable(_iOS54, _macOS51_0) { } // expected-error {{availability macro cannot be used in an '@inlinable' function}}
  if #unavailable(iOS 54.0, _macOS51_0, tvOS 54.0) { } // expected-error {{availability macro cannot be used in an '@inlinable' function}}
  doIt {
    if #available(_iOS54Aligned, *) { } // expected-error {{availability macro cannot be used in an '@inlinable' function}}
  }
}

@_alwaysEmitIntoClient
public func forbidMacrosInInlinableCode1() {
  if #available(_iOS54Aligned, *) { } // expected-error {{availability macro cannot be used in an '@_alwaysEmitIntoClient' function}}
  if #available(_iOS54, _macOS51_0, *) { } // expected-error {{availability macro cannot be used in an '@_alwaysEmitIntoClient' function}}
  if #available(iOS 54.0, _macOS51_0, tvOS 54.0, *) { } // expected-error {{availability macro cannot be used in an '@_alwaysEmitIntoClient' function}}
  if #unavailable(_iOS54Aligned) { } // expected-error {{availability macro cannot be used in an '@_alwaysEmitIntoClient' function}}
  if #unavailable(_iOS54, _macOS51_0) { } // expected-error {{availability macro cannot be used in an '@_alwaysEmitIntoClient' function}}
  if #unavailable(iOS 54.0, _macOS51_0, tvOS 54.0) { } // expected-error {{availability macro cannot be used in an '@_alwaysEmitIntoClient' function}}
  doIt {
    if #available(_iOS54Aligned, *) { } // expected-error {{availability macro cannot be used in an '@_alwaysEmitIntoClient' function}}
  }
}

@available(_iOS53Aligned, *)
@backDeployed(before: _iOS54Aligned)
public func forbidMacrosInInlinableCode2() {
  if #available(_iOS54Aligned, *) { } // expected-error {{availability macro cannot be used in a '@backDeployed' function}}
  if #available(_iOS54, _macOS51_0, *) { } // expected-error {{availability macro cannot be used in a '@backDeployed' function}}
  if #available(iOS 54.0, _macOS51_0, tvOS 54.0, *) { } // expected-error {{availability macro cannot be used in a '@backDeployed' function}}
  if #unavailable(_iOS54Aligned) { } // expected-error {{availability macro cannot be used in a '@backDeployed' function}}
  if #unavailable(_iOS54, _macOS51_0) { } // expected-error {{availability macro cannot be used in a '@backDeployed' function}}
  if #unavailable(iOS 54.0, _macOS51_0, tvOS 54.0) { } // expected-error {{availability macro cannot be used in a '@backDeployed' function}}
  doIt {
    if #available(_iOS54Aligned, *) { } // expected-error {{availability macro cannot be used in a '@backDeployed' function}}
  }
}