forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavailability_query.swift
106 lines (68 loc) · 3.75 KB
/
availability_query.swift
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
// RUN: %target-typecheck-verify-swift
// REQUIRES: OS=macosx
if #available(OSX 10.51, *) {
}
// Disallow use as an expression.
if (#available(OSX 10.51, *)) {} // expected-error {{#available may only be used as condition of an 'if', 'guard'}}
let x = #available(OSX 10.51, *) // expected-error {{#available may only be used as condition of}}
(#available(OSX 10.51, *) ? 1 : 0) // expected-error {{#available may only be used as condition of an}}
if !#available(OSX 10.52, *) { // expected-error {{#available may only be used as condition of an}}
}
if let _ = Optional(5), !#available(OSX 10.52, *) { // expected-error {{#available may only be used as condition}}
}
if #available(OSX 10.51, *) && #available(OSX 10.52, *) { // expected-error {{expected ',' joining parts of a multi-clause condition}} {{28-31=,}}
}
if #available { // expected-error {{expected availability condition}} expected-error {{closure expression is unused}} expected-error {{top-level statement cannot begin with a closure expression}} expected-note {{did you mean to use a 'do' statement?}} {{15-15=do }}
}
if #available( { // expected-error {{expected platform name}} expected-error {{expected ')'}} expected-note {{to match this opening '('}}
}
if #available() { // expected-error {{expected platform name}}
}
if #available(OSX { // expected-error {{expected version number}} expected-error {{expected ')'}} expected-note {{to match this opening '('}}
}
if #available(OSX) { // expected-error {{expected version number}}
}
if #available(OSX 10.51 { // expected-error {{expected ')'}} expected-note {{to match this opening '('}} expected-error {{must handle potential future platforms with '*'}} {{24-24=, *}}
}
if #available(iDishwasherOS 10.51) { // expected-error {{unrecognized platform name 'iDishwasherOS'}}
}
if #available(iDishwasherOS 10.51, *) { // expected-error {{unrecognized platform name 'iDishwasherOS'}}
}
if #available(OSX 10.51, OSX 10.52, *) { // expected-error {{version for 'OSX' already specified}}
}
if #available(OSX 10.52) { } // expected-error {{must handle potential future platforms with '*'}} {{24-24=, *}}
if #available(OSX 10.51, iOS 8.0) { } // expected-error {{must handle potential future platforms with '*'}} {{33-33=, *}}
if #available(iOS 8.0, *) {
}
// Want to make sure we can parse this. Perhaps we should not let this validate, though.
if #available(*) {
}
if #available(* { // expected-error {{expected ')' in availability query}} expected-note {{to match this opening '('}}
}
// Multiple platforms
if #available(OSX 10.51, iOS 8.0, *) {
}
if #available(OSX 10.51, { // expected-error {{expected platform name}} // expected-error {{expected ')'}} expected-note {{to match this opening '('}}
}
if #available(OSX 10.51,) { // expected-error {{expected platform name}}
}
if #available(OSX 10.51, iOS { // expected-error {{expected version number}} // expected-error {{expected ')'}} expected-note {{to match this opening '('}}
}
if #available(OSX 10.51, iOS 8.0, iDishwasherOS 10.51) { // expected-error {{unrecognized platform name 'iDishwasherOS'}}
}
if #available(iDishwasherOS 10.51, OSX 10.51) { // expected-error {{unrecognized platform name 'iDishwasherOS'}}
}
if #available(OSX 10.51 || iOS 8.0) {// expected-error {{'||' cannot be used in an availability condition}}
}
// Emit Fix-It removing un-needed >=, for the moment.
if #available(OSX >= 10.51, *) { // expected-error {{version comparison not needed}} {{19-22=}}
}
// <rdar://problem/20904820> Following a "let" condition with #available is incorrectly rejected
// Bool then #available.
if 1 != 2, #available(iOS 8.0, *) {}
// Pattern then #available(iOS 8.0, *) {
if case 42 = 42, #available(iOS 8.0, *) {}
if let _ = Optional(42), #available(iOS 8.0, *) {}
// Allow "macOS" as well.
if #available(macOS 10.51, *) {
}