|
1 |
| -// RUN: %target-typecheck-verify-swift |
| 1 | +// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macos10.15 |
2 | 2 | // REQUIRES: OS=macosx
|
3 | 3 | // <rdar://problem/17669805> Suggest narrowing the range of bad availabile checks
|
4 | 4 |
|
5 | 5 | import Foundation
|
6 | 6 |
|
7 |
| -@available(macOS 10.50.2, *) |
| 7 | +@available(macOS 50.2, *) |
8 | 8 | func foo() { }
|
9 | 9 |
|
10 | 10 | func useFoo() {
|
11 |
| - if #available(macOS 10.50.1, *) { |
12 |
| - foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-1:23-30=10.50.2}} |
| 11 | + if #available(macOS 50.1, *) { |
| 12 | + foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-1:23-27=50.2}} |
13 | 13 | }
|
14 | 14 | }
|
15 | 15 |
|
16 | 16 | func useFooDifferentSpelling() {
|
17 |
| - if #available(OSX 10.50.1, *) { |
18 |
| - foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-1:21-28=10.50.2}} |
| 17 | + if #available(OSX 50.1, *) { |
| 18 | + foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-1:21-25=50.2}} |
19 | 19 | }
|
20 | 20 | }
|
21 | 21 |
|
22 | 22 | func useFooAlreadyOkRange() {
|
23 |
| - if #available(OSX 10.51, *) { |
| 23 | + if #available(OSX 51, *) { |
24 | 24 | foo()
|
25 | 25 | }
|
26 | 26 | }
|
27 | 27 |
|
28 | 28 | func useFooUnaffectedSimilarText() {
|
29 |
| - if #available(iOS 10.50.10, OSX 10.50.1, *) { |
30 |
| - foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-1:35-42=10.50.2}} |
| 29 | + if #available(iOS 50.10, OSX 50.1, *) { |
| 30 | + foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-1:32-36=50.2}} |
31 | 31 | }
|
32 | 32 | }
|
33 | 33 |
|
34 | 34 | func useFooWayOff() {
|
35 |
| - // expected-note@-1{{add @available attribute to enclosing global function}} |
| 35 | + // expected-note@-1 2 {{add @available attribute to enclosing global function}} |
36 | 36 | if #available(OSX 10.10, *) {
|
37 |
| - foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} |
| 37 | + foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} |
| 38 | + // expected-note@-1{{add 'if #available' version check}} |
| 39 | + } |
| 40 | + |
| 41 | + if #available(OSX 49.0, *) { |
| 42 | + foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} |
38 | 43 | // expected-note@-1{{add 'if #available' version check}}
|
39 | 44 | }
|
40 | 45 | }
|
41 | 46 |
|
42 |
| -@available(OSX 10.50, *) |
| 47 | +@available(OSX 50, *) |
43 | 48 | class FooUser {
|
44 | 49 | func useFoo() {
|
45 |
| - foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-3:16-21=10.50.2}} |
| 50 | + foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-3:16-18=50.2}} |
46 | 51 | }
|
47 | 52 | }
|
48 | 53 |
|
49 |
| -@available(OSX, introduced: 10.50, obsoleted: 10.50.4) |
| 54 | +@available(OSX, introduced: 50, obsoleted: 50.4) |
50 | 55 | class FooUser2 {
|
51 | 56 | func useFoo() {
|
52 |
| - foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-3:29-34=10.50.2}} |
| 57 | + foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-3:29-31=50.2}} |
53 | 58 | }
|
54 | 59 | }
|
55 | 60 |
|
56 |
| -@available(OSX, introduced: 10.50, obsoleted: 10.50.4) |
| 61 | +@available(OSX, introduced: 50, obsoleted: 50.4) |
57 | 62 | @objc
|
58 | 63 | class FooUser3 : NSObject {
|
59 | 64 | func useFoo() {
|
60 |
| - foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-4:29-34=10.50.2}} |
| 65 | + foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-4:29-31=50.2}} |
61 | 66 | }
|
62 | 67 | }
|
63 | 68 |
|
64 |
| -@available(OSX, introduced: 10.50.4) |
| 69 | +@available(OSX, introduced: 50.4) |
65 | 70 | class FooUserOkRange {
|
66 | 71 | func useFoo() {
|
67 | 72 | foo()
|
68 | 73 | }
|
69 | 74 | }
|
| 75 | + |
| 76 | +@available(macOS 10.50.2, *) |
| 77 | +func foo10() { } |
| 78 | + |
| 79 | +func useFoo10() { |
| 80 | + if #available(macOS 10.50.1, *) { |
| 81 | + foo10() // expected-error {{'foo10()' is only available in macOS 10.50.2 or newer}} {{-1:23-30=10.50.2}} |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +func useFoo10WayOff() { |
| 86 | + // expected-note@-1 3 {{add @available attribute to enclosing global function}} |
| 87 | + if #available(OSX 10.10, *) { |
| 88 | + foo10() // expected-error {{'foo10()' is only available in macOS 10.50.2 or newer}} |
| 89 | + // expected-note@-1{{add 'if #available' version check}} |
| 90 | + } |
| 91 | + |
| 92 | + if #available(OSX 10.49.0, *) { |
| 93 | + foo10() // expected-error {{'foo10()' is only available in macOS 10.50.2 or newer}} |
| 94 | + // expected-note@-1{{add 'if #available' version check}} |
| 95 | + } |
| 96 | + |
| 97 | + if #available(OSX 9, *) { |
| 98 | + foo10() // expected-error {{'foo10()' is only available in macOS 10.50.2 or newer}} |
| 99 | + // expected-note@-1{{add 'if #available' version check}} |
| 100 | + } |
| 101 | +} |
0 commit comments