-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathconditional_compiliation_expr.swift
120 lines (100 loc) · 4.59 KB
/
conditional_compiliation_expr.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// RUN: %target-typecheck-verify-swift -D FOO -swift-version 3
// ---------------------------------------------------------------------------
// Invalid binary operation
#if FOO = false
// expected-warning @-1 {{ignoring invalid conditional compilation expression, which will be rejected in future version of Swift}}
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}
#else
undefinedFunc() // ignored.
#endif
#if false
#elseif !FOO ? false : true
// expected-warning @-1 {{ignoring invalid conditional compilation expression, which will be rejected in future version of Swift}}
undefinedFunc() // ignored.
#else
undefinedFunc() // expected-error {{use of unresolved identifier 'undefinedFunc'}}
#endif
// ---------------------------------------------------------------------------
// SR-3663: The precedence and associativity of '||' and '&&'.
// See test/Parse/ConditionalCompilation/sequence.swift for Swift 4 behavior.
// expected-warning @+1 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{14-14=(}} {{27-27=)}}
#if false || true && false
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
#else
undefinedElse()
#endif
// expected-warning @+1 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{5-5=(}} {{18-18=)}}
#if false && true || true
undefinedIf()
#else
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
#endif
// expected-warning @+1 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{14-14=(}} {{27-27=)}}
#if false || true && false || false
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
#else
undefinedElse()
#endif
// expected-warning @+1 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{5-5=(}} {{18-18=)}} {{22-22=(}} {{42-42=)}}
#if true && false || true && true && true
undefinedIf()
#else
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
#endif
// Accepted in Swift3. *source breaking*
#if false || true && try! Swift
// expected-error @-1 {{invalid conditional compilation expression}}
// expected-warning @-2 {{future version of Swift have different rule for evaluating condition; add parentheses to make the condition compatible with Swift4}} {{14-14=(}} {{32-32=)}}
undefinedIf()
#endif
// ---------------------------------------------------------------------------
// SR-4032: "skip parsing" in non-active branch for version checks.
// See test/Parse/ConditionalCompilation/sequence_version.swift for Swift 4 behavior.
#if !swift(>=2.2)
// There should be no error here.
foo bar
#else
let _: Int = 1
#endif
#if (swift(>=2.2))
let _: Int = 1
#else
// There should be no error here.
foo bar
#endif
#if swift(>=99.0) || swift(>=88.1.1)
// There should be no error here.
foo bar baz // expected-error 2 {{consecutive statements}}
#else
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
#endif
#if swift(>=99.0) || FOO
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
#else
undefinedElse()
#endif
#if swift(>=99.0) && FOO
// There should be no error here.
foo bar baz // expected-error 2 {{consecutive statements}}
#else
undefinedElse() // expected-error {{use of unresolved identifier 'undefinedElse'}}
#endif
#if FOO && swift(>=2.2)
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
#else
// There should be no error here.
foo bar baz // expected-error 2 {{consecutive statements}}
#endif
#if swift(>=2.2) && swift(>=1)
undefinedIf() // expected-error {{use of unresolved identifier 'undefinedIf'}}
#else
// There should be no error here.
foo bar baz // expected-error 2 {{consecutive statements}}
#endif
// ---------------------------------------------------------------------------
// SR-4031: Compound name in compilation condition
// See test/Parse/ConditionalCompilation/compoundName_swift4.swift for Swfit 4 behavior
#if BAR(_:) // expected-warning {{ignoring parentheses in compound name, which will be rejected in future version of Swift}} {{8-12=}}
#elseif os(x:)(macOS) // expected-warning {{ignoring parentheses in compound name, which will be rejected in future version of Swift}} {{11-15=}}
#elseif os(Linux(foo:bar:)) // expected-warning {{ignoring parentheses in compound name, which will be rejected in future version of Swift}} {{17-27=}}
#endif