You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Parser] Support "<" unary operator in #if swift() expressions
Until now, only ">=" was supported in #if swift() expressions, for example:
```#if swift(>=2.1)
```#endif
This means that if we want to evaluate code only when the language version is
less than a particular version we need to do the following:
```#if !swift(>=2.1)
```#endif
An alernative to make this more readable (the "!" can be easily missed in a code
review) is to introduce another supported unary operator, "<". The previous
example could be rewritten like this:
```#if swift(<2.1)
```#endif
This commit adds support for that unary operator, along with some tests.
Copy file name to clipboardExpand all lines: test/Parse/ConditionalCompilation/language_version.swift
+25-3Lines changed: 25 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,20 @@
7
7
asdf asdf asdf asdf
8
8
#endif
9
9
10
+
#if swift(<1.2)
11
+
#endif
12
+
13
+
#if swift(<4.2)
14
+
leta=1
15
+
#else
16
+
leta=2
17
+
#endif
18
+
19
+
#if swift(<1.0)
20
+
// This shouldn't emit any diagnostics.
21
+
asdf asdf asdf asdf
22
+
#endif
23
+
10
24
#if swift(>=1.2)
11
25
12
26
#if os(iOS)
@@ -34,13 +48,21 @@
34
48
%#^*&
35
49
#endif
36
50
37
-
#if swift(">=7.1") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
51
+
#if !swift(<1000.0)
52
+
// This shouldn't emit any diagnostics.
53
+
%#^*&
54
+
#endif
55
+
56
+
#if swift(">=7.1") // expected-error {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
57
+
#endif
58
+
59
+
#if swift("<7.1") // expected-error {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
38
60
#endif
39
61
40
-
#if swift(">=2n.2") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
62
+
#if swift(">=2n.2") // expected-error {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
41
63
#endif
42
64
43
-
#if swift("") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
65
+
#if swift("") // expected-error {{unexpected platform condition argument: expected a unary comparison '>=' or '<'; for example, '>=2.2' or '<2.2'}}
0 commit comments