@@ -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
@@ -41,6 +54,21 @@ _ = /x
41
54
_ = !/ x/
42
55
// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
43
56
57
+ _ = ( !/ x/ )
58
+ // expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
59
+
60
+ _ = !/ /
61
+ // expected-error@-1 {{unary operator cannot be separated from its operand}}
62
+ // expected-error@-2 {{cannot find operator '!/' in scope}}
63
+ // expected-error@-3 {{unterminated regex literal}}
64
+
65
+ _ = !!/ x/
66
+ _ = ( !!/ x/ )
67
+
68
+ _ = /^ )
69
+ // expected-error@-1 {{unterminated regex literal}}
70
+ // expected-error@-2 {{closing ')' does not balance any groups openings}}
71
+
44
72
_ = /x/ ! // expected-error {{cannot force unwrap value of non-optional type 'Regex<Substring>'}}
45
73
_ = /x/ + /y/ // expected-error {{binary operator '+' cannot be applied to two 'Regex<Substring>' operands}}
46
74
@@ -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 3 {{'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,23 @@ 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
+ // TODO: Should we do prefix operator splitting here?
284
+ baz ( ^^/ , / )
285
+ baz ( ( ^^/ ) , / )
286
+
245
287
func bazbaz( _ x: ( Int , Int ) -> Int , _ y: Int ) { }
246
288
bazbaz ( / , 0 )
289
+ bazbaz ( ^^/ , 0 )
247
290
248
291
func qux< T> ( _ x: ( Int , Int ) -> Int , _ y: T ) -> Int { 0 }
249
292
do {
@@ -257,6 +300,23 @@ do {
257
300
// expected-error@-2:21 {{expected ',' separator}}
258
301
}
259
302
_ = qux ( / , 1 ) // this comment tests to make sure we don't try and end the regex on the starting '/' of '//'.
303
+ _ = qux ( / , 1 ) /* same thing with a block comment */
304
+
305
+ func quxqux( _ x: ( Int , Int ) -> Int ) { }
306
+ quxqux ( /^/ ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
307
+ quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
308
+ quxqux ( { $0 /^/ $1 } )
309
+
310
+ // FIXME: We should be able to do operator splitting here and form `!(/^/)`.
311
+ quxqux ( !/^/ ) // expected-error {{unary operators must not be juxtaposed; parenthesize inner expression}}
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