File: attr_availability_watchos.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 (93 lines) | stat: -rw-r--r-- 3,625 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
// RUN: %swift -typecheck -verify -parse-stdlib -target i386-apple-watchos2.0 %s

@available(watchOS, introduced: 1.0, deprecated: 1.5, obsoleted: 2.0,
              message: "you don't want to do that anyway")
func doSomething() { }
// expected-note @-1{{'doSomething()' was obsoleted in watchOS 2.0}}

doSomething() // expected-error{{'doSomething()' is unavailable in watchOS: you don't want to do that anyway}}

// Preservation of major.minor.micro
@available(watchOS, introduced: 1.0, deprecated: 1.5, obsoleted: 1.5.3)
func doSomethingElse() { }
// expected-note @-1{{'doSomethingElse()' was obsoleted in watchOS 1.5.3}}

doSomethingElse() // expected-error{{'doSomethingElse()' is unavailable in watchOS}}

// Preservation of minor-only version
@available(watchOS, introduced: 1.0, deprecated: 1.5, obsoleted: 2)
func doSomethingReallyOld() { }
// expected-note @-1{{'doSomethingReallyOld()' was obsoleted in watchOS 2}}

doSomethingReallyOld() // expected-error{{'doSomethingReallyOld()' is unavailable in watchOS}}

// Test deprecations in 2.0 and later

@available(watchOS, introduced: 1.1, deprecated: 2.0,
              message: "Use another function")
func deprecatedFunctionWithMessage() { }

deprecatedFunctionWithMessage() // expected-warning{{'deprecatedFunctionWithMessage()' was deprecated in watchOS 2.0: Use another function}}


@available(watchOS, introduced: 1.0, deprecated: 2.0)
func deprecatedFunctionWithoutMessage() { }

deprecatedFunctionWithoutMessage() // expected-warning{{'deprecatedFunctionWithoutMessage()' was deprecated in watchOS 2.0}}

@available(watchOS, introduced: 1.0, deprecated: 2.0,
              message: "Use BetterClass instead")
class DeprecatedClass { }

func functionWithDeprecatedParameter(p: DeprecatedClass) { } // expected-warning{{'DeprecatedClass' was deprecated in watchOS 2.0: Use BetterClass instead}}

@available(watchOS, introduced: 2.0, deprecated: 4.0,
              message: "Use BetterClass instead")
class DeprecatedClassIn3_0 { }

// Elements deprecated later than the minimum deployment target (which is 2.0, in this case) should not generate warnings
func functionWithDeprecatedLaterParameter(p: DeprecatedClassIn3_0) { }

// Treat watchOS as distinct from iOS in availability queries

@available(watchOS, introduced: 2.2)
func functionIntroducedOnwatchOS2_2() { }

if #available(iOS 9.3, *) {
  functionIntroducedOnwatchOS2_2() // expected-error {{'functionIntroducedOnwatchOS2_2()' is only available in watchOS 2.2 or newer}}
      // expected-note@-1 {{add 'if #available' version check}}
}

if #available(iOS 9.3, watchOS 2.1, *) {
  functionIntroducedOnwatchOS2_2() // expected-error {{'functionIntroducedOnwatchOS2_2()' is only available in watchOS 2.2 or newer}} {{-1:32-35=2.2}}
}

if #available(iOS 9.1, watchOS 2.2, *) {
  functionIntroducedOnwatchOS2_2()
}

if #available(iOS 8.0, watchOS 2.2, *) {
}

if #available(iOS 9.2, watchOS 1.0, *) { // no-warning
}


// Swift-originated iOS availability attributes should not be transcribed to watchOS

@available(iOS, unavailable)
func swiftOriginatedFunctionUnavailableOnIOS() { }

@available(iOS, introduced: 6.0, deprecated: 9.0)
func swiftOriginatedFunctionDeprecatedOnIOS() { }

@available(iOS, introduced: 10.0)
func swiftOriginatedFunctionPotentiallyUnavailableOnIOS() { }

func useSwiftOriginatedFunctions() {
  // We do not expect diagnostics here because iOS availability attributes coming from
  // Swift should not be transcribed to watchOS.
  swiftOriginatedFunctionUnavailableOnIOS()
  swiftOriginatedFunctionDeprecatedOnIOS()
  swiftOriginatedFunctionPotentiallyUnavailableOnIOS()
}