@@ -6,13 +6,26 @@ prefix operator / // expected-error {{prefix operator may not contain '/'}}
6
6
prefix operator ^/ // expected-error {{prefix operator may not contain '/'}}
7
7
prefix operator /^/ // expected-error {{prefix operator may not contain '/'}}
8
8
9
+ prefix operator !!
10
+ prefix func !! < T> ( _ x: T ) -> T { x }
11
+
12
+ prefix operator ^^
13
+ prefix func ^^ < T> ( _ x: T ) -> T { x }
14
+
9
15
precedencegroup P {
10
16
associativity : left
11
17
}
12
18
13
- // Fine.
19
+ // The divisions in the body of the below operators make sure we don't try and
20
+ // consider them to be ending delimiters of a regex.
14
21
infix operator /^/ : P
15
- func /^/ ( lhs: Int , rhs: Int ) -> Int { 0 }
22
+ func /^/ ( lhs: Int , rhs: Int ) -> Int { 1 / 2 }
23
+
24
+ infix operator /^ : P
25
+ func /^ ( lhs: Int , rhs: Int ) -> Int { 1 / 2 }
26
+
27
+ infix operator ^^/ : P
28
+ func ^^/ ( lhs: Int , rhs: Int ) -> Int { 1 / 2 }
16
29
17
30
let i = 0 /^/ 1 /^/ 3
18
31
@@ -22,32 +35,53 @@ _ = /x/.self
22
35
_ = /\/ /
23
36
_ = /\\/
24
37
25
- // These unfortunately become infix `=/`. We could likely improve the diagnostic
26
- // though.
27
- let z =/ 0 /
28
- // expected-error@-1 {{type annotation missing in pattern}}
29
- // expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
30
- // expected-error@-3 {{expected expression after unary operator}}
31
- // expected-error@-4 {{cannot find operator '=/' in scope}}
32
- // expected-error@-5 {{'/' is not a postfix unary operator}}
33
- _=/ 0 /
34
- // expected-error@-1 {{'_' can only appear in a pattern or on the left side of an assignment}}
35
- // expected-error@-2 {{cannot find operator '=/' in scope}}
36
- // expected-error@-3 {{'/' is not a postfix unary operator}}
38
+ // This is just here to appease typo correction.
39
+ let y = 0
40
+
41
+ // These unfortunately become prefix `=` and infix `=/` respectively. We could
42
+ // likely improve the diagnostic though.
43
+ do {
44
+ let z =/0 /
45
+ // expected-error@-1 {{type annotation missing in pattern}}
46
+ // expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
47
+ // expected-error@-3 {{expected expression}}
48
+ }
49
+ do {
50
+ _=/ 0 /
51
+ // expected-error@-1 {{'_' can only appear in a pattern or on the left side of an assignment}}
52
+ // expected-error@-2 {{cannot find operator '=/' in scope}}
53
+ // expected-error@-3 {{'/' is not a postfix unary operator}}
54
+ }
37
55
38
56
_ = / x
39
57
// expected-error@-1 {{unterminated regex literal}}
40
58
41
59
_ = !/ x/
42
60
// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
43
61
62
+ _ = ( !/ x/ )
63
+ // expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
64
+
65
+ _ = !/ /
66
+ // expected-error@-1 {{regex literal may not start with space; add backslash to escape}}
67
+ // expected-error@-2 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
68
+
69
+ _ = !!/ /
70
+ // expected-error@-1 {{regex literal may not start with space; add backslash to escape}}
71
+
72
+ _ = !!/ x/
73
+ _ = ( !!/ x/ )
74
+
75
+ _ = /^ )
76
+ // expected-error@-1 {{unterminated regex literal}}
77
+ // expected-error@-2 {{closing ')' does not balance any groups openings}}
78
+
44
79
_ = /x/ ! // expected-error {{cannot force unwrap value of non-optional type 'Regex<Substring>'}}
45
80
_ = /x/ + /y/ // expected-error {{binary operator '+' cannot be applied to two 'Regex<Substring>' operands}}
46
81
47
82
_ = /x/ +/ y/
48
83
// expected-error@-1 {{cannot find operator '+/' in scope}}
49
84
// expected-error@-2 {{'/' is not a postfix unary operator}}
50
- // expected-error@-3 {{cannot find 'y' in scope}}
51
85
52
86
_ = /x/ ? . blah
53
87
// expected-error@-1 {{cannot use optional chaining on non-optional value of type 'Regex<Substring>'}}
@@ -74,7 +108,6 @@ _ = /x/ ... /y/ // expected-error {{referencing operator function '...' on 'Comp
74
108
_ = /x/ .../ y/
75
109
// expected-error@-1 {{missing whitespace between '...' and '/' operators}}
76
110
// expected-error@-2 {{'/' is not a postfix unary operator}}
77
- // expected-error@-3 {{cannot find 'y' in scope}}
78
111
79
112
_ = / x / ...
80
113
// expected-error@-1 {{unary operator '...' cannot be applied to an operand of type 'Regex<Substring>'}}
@@ -92,12 +125,7 @@ func foo<T>(_ x: T, y: T) {}
92
125
foo ( /abc/ , y: / abc / )
93
126
94
127
func bar< T> ( _ x: inout T ) { }
95
-
96
- // TODO: We split this into a prefix '&', but inout is handled specially when
97
- // parsing an argument list. This shouldn't matter anyway, but we should at
98
- // least have a custom diagnostic.
99
- bar ( &/ x/ )
100
- // expected-error@-1 {{'&' is not a prefix unary operator}}
128
+ bar ( &/ x/ ) // expected-error {{cannot pass immutable value as inout argument: literals are not mutable}}
101
129
102
130
struct S {
103
131
subscript( x: Regex < Substring > ) -> Void { ( ) }
@@ -233,7 +261,7 @@ _ = /x/*comment*/
233
261
// expected-error@-1 {{unterminated regex literal}}
234
262
235
263
// These become regex literals, unless surrounded in parens.
236
- func baz( _ x: ( Int, Int) - > Int, _ y: ( Int, Int) - > Int) { } // expected-note 2 {{'baz' declared here}}
264
+ func baz( _ x: ( Int, Int) - > Int, _ y: ( Int, Int) - > Int) { } // expected-note 4 {{'baz' declared here}}
237
265
baz ( / , / )
238
266
// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
239
267
// expected-error@-2 {{missing argument for parameter #2 in call}}
@@ -242,8 +270,22 @@ baz(/,/)
242
270
// expected-error@-2 {{missing argument for parameter #2 in call}}
243
271
baz ( ( / ) , / )
244
272
273
+ baz ( /^ , / )
274
+ // expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
275
+ // expected-error@-2 {{missing argument for parameter #2 in call}}
276
+
277
+ do {
278
+ baz ( ( /^ ) , / )
279
+ // expected-error@-1 {{closing ')' does not balance any groups openings}}
280
+ // expected-note@-2 {{to match this opening '('}}
281
+ } // expected-error {{expected ')' in expression list}}
282
+
283
+ baz ( ^^/ , / ) // expected-error {{missing argument for parameter #2 in call}}
284
+ baz ( ( ^^/ ) , / )
285
+
245
286
func bazbaz( _ x: ( Int , Int ) -> Int , _ y: Int ) { }
246
287
bazbaz ( / , 0 )
288
+ bazbaz ( ^^/ , 0 )
247
289
248
290
func qux< T> ( _ x: ( Int , Int ) -> Int , _ y: T ) -> Int { 0 }
249
291
do {
@@ -257,6 +299,24 @@ do {
257
299
// expected-error@-2:21 {{expected ',' separator}}
258
300
}
259
301
_ = qux ( / , 1 ) // this comment tests to make sure we don't try and end the regex on the starting '/' of '//'.
302
+ _ = qux ( / , 1 ) /* same thing with a block comment */
303
+
304
+ func quxqux( _ x: ( Int , Int ) -> Int ) { }
305
+ quxqux ( /^/ ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
306
+ quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
307
+ quxqux ( { $0 /^/ $1 } )
308
+
309
+ quxqux ( !/^/ )
310
+ // expected-error@-1 {{cannot convert value of type 'Bool' to expected argument type '(Int, Int) -> Int'}}
311
+ // expected-error@-2 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
312
+
313
+ quxqux ( /^ )
314
+
315
+ do {
316
+ quxqux ( /^ ) / 1
317
+ // expected-error@-1 {{closing ')' does not balance any groups openings}}
318
+ // expected-error@-2 {{expected ',' separator}}
319
+ }
260
320
261
321
let arr : [ Double ] = [ 2 , 3 , 4 ]
262
322
_ = arr. reduce ( 1 , / ) / 3
@@ -284,3 +344,15 @@ _ = /0oG/
284
344
_ = /"/
285
345
_ = /'/
286
346
_ = / < #placeholder#>/
347
+
348
+ _ = ^^/ 0 xG/
349
+ _ = ^^/ 0 oG/
350
+ _ = ^^/ " /
351
+ _ = ^^/'/
352
+ _ = ^^/<#placeholder#>/
353
+
354
+ _ = (^^/0xG/)
355
+ _ = (^^/0oG/)
356
+ _ = (^^/ " / )
357
+ _ = ( ^^/ '/ )
358
+ _ = ( ^^/ < #placeholder#>/ )
0 commit comments