@@ -6,6 +6,8 @@ prefix operator /
6
6
prefix operator ^/
7
7
prefix operator /^/
8
8
9
+ prefix func ^/ < T> ( _ x: T ) -> T { x } // expected-note {{'^/' declared here}}
10
+
9
11
prefix operator !!
10
12
prefix func !! < T> ( _ x: T ) -> T { x }
11
13
@@ -259,6 +261,8 @@ _ = /x // comment
259
261
_ = /x/ * comment*/
260
262
// expected-error@-1 {{'/' is not a prefix unary operator}}
261
263
264
+ // MARK: Unapplied operators
265
+
262
266
// These become regex literals, unless surrounded in parens.
263
267
func baz( _ x: ( Int, Int) - > Int, _ y: ( Int, Int) - > Int) { } // expected-note 4{{'baz' declared here}}
264
268
baz ( / , / )
@@ -273,11 +277,7 @@ baz(/^, /)
273
277
// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
274
278
// expected-error@-2 {{missing argument for parameter #2 in call}}
275
279
276
- do {
277
- baz ( ( /^ ) , / )
278
- // expected-error@-1 {{closing ')' does not balance any groups openings}}
279
- // expected-note@-2 {{to match this opening '('}}
280
- } // expected-error {{expected ')' in expression list}}
280
+ baz ( ( /^ ) , / )
281
281
282
282
baz ( ^^/ , / ) // expected-error {{missing argument for parameter #2 in call}}
283
283
baz ( ( ^^/ ) , / )
@@ -287,20 +287,18 @@ bazbaz(/, 0)
287
287
bazbaz ( ^^/ , 0 )
288
288
289
289
func qux< T> ( _ x: ( Int , Int ) -> Int , _ y: T ) -> Int { 0 }
290
- do {
291
- _ = qux ( / , 1 ) / 2
292
- // expected-error@-1:15 {{cannot parse regular expression: closing ')' does not balance any groups openings}}
293
- // expected-error@-2:19 {{expected ',' separator}}
294
- }
290
+ _ = qux ( / , 1 ) / 2
295
291
do {
296
292
_ = qux ( / , " ( " ) / 2
297
293
// expected-error@-1 {{cannot convert value of type 'Regex<(Substring, Substring)>' to expected argument type '(Int, Int) -> Int'}}
298
294
// expected-error@-2:21 {{expected ',' separator}}
299
295
}
296
+ _ = qux ( ( / ) , " ( " ) / 2
300
297
_ = qux ( / , 1 ) // this comment tests to make sure we don't try and end the regex on the starting '/' of '//'.
301
298
_ = qux ( / , 1 ) /* same thing with a block comment */
302
299
303
- func quxqux( _ x: ( Int , Int ) -> Int ) { }
300
+ @discardableResult
301
+ func quxqux( _ x: ( Int , Int ) -> Int ) -> Int { 0 }
304
302
quxqux ( /^/ ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
305
303
quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
306
304
quxqux ( { $0 /^/ $1 } )
@@ -310,17 +308,88 @@ quxqux(!/^/)
310
308
// expected-error@-2 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
311
309
312
310
quxqux ( /^ )
313
-
314
- do {
315
- quxqux ( /^ ) / 1
316
- // expected-error@-1 {{closing ')' does not balance any groups openings}}
317
- // expected-error@-2 {{expected ',' separator}}
318
- }
311
+ _ = quxqux ( /^ ) / 1
319
312
320
313
let arr : [ Double ] = [ 2 , 3 , 4 ]
321
314
_ = arr. reduce ( 1 , / ) / 3
322
315
_ = arr. reduce ( 1 , / ) + arr. reduce ( 1 , / )
323
316
317
+ // MARK: ')' disambiguation behavior
318
+
319
+ _ = ( / x)
320
+ // expected-error@-1 {{'/' is not a prefix unary operator}}
321
+
322
+ _ = ( /x)/
323
+ // expected-error@-1 {{'/' is not a prefix unary operator}}
324
+ // expected-error@-2 {{'/' is not a postfix unary operator}}
325
+
326
+ _ = ( /[(0)])/
327
+ // expected-error@-1 {{'/' is not a prefix unary operator}}
328
+ // expected-error@-2 {{'/' is not a postfix unary operator}}
329
+
330
+ _ = /[(0)]/
331
+ _ = /(x)/
332
+ _ = /[)]/
333
+ _ = /[a\])]/
334
+ _ = /([)])/
335
+ _ = /]]][)]/
336
+
337
+ _ = /
338
+ // expected-error@-1 {{unterminated regex literal}}
339
+
340
+ _ = / )
341
+ // expected-error@-1 {{unterminated regex literal}}
342
+ // expected-error@-2 {{closing ')' does not balance any groups openings}}
343
+
344
+ let fn : ( Int , Int ) -> Int = ( / )
345
+
346
+ _ = /\()/
347
+ // expected-error@-1 {{'/' is not a prefix unary operator}}
348
+ // expected-error@-2 {{'/' is not a postfix unary operator}}
349
+ // expected-error@-3 {{invalid component of Swift key path}}
350
+
351
+ do {
352
+ let _: Regex = ( /whatever\)/
353
+ // expected-note@-1 {{to match this opening '('}}
354
+ } // expected-error {{expected ')' in expression list}}
355
+ do {
356
+ _ = /(()()))/
357
+ // expected-error@-1 {{'/' is not a prefix unary operator}}
358
+ // expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
359
+ // expected-error@-3 {{expected expression}}
360
+ }
361
+ do {
362
+ _ = /[x])/
363
+ // expected-error@-1 {{'/' is not a prefix unary operator}}
364
+ // expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
365
+ // expected-error@-3 {{expected expression}}
366
+ }
367
+ do {
368
+ _ = /[\]])/
369
+ // expected-error@-1 {{expected expression path in Swift key path}}
370
+ }
371
+
372
+ _ = ^/ x/
373
+ // expected-error@-1 {{'^' is not a prefix unary operator}}
374
+
375
+ _ = ( ^/ x) /
376
+ // expected-error@-1 {{'/' is not a postfix unary operator}}
377
+
378
+ _ = ( !!/ x/ )
379
+
380
+ _ = ^/ " / "
381
+ // expected-error@-1 {{'^' is not a prefix unary operator}}
382
+ // expected-error@-2 {{unterminated string literal}}
383
+
384
+ _ = ^/ " [/ "
385
+ // expected-error@-1 {{'^' is not a prefix unary operator}}
386
+ // expected-error@-2 {{unterminated string literal}}
387
+ // expected-error@-3 {{expected custom character class members}}
388
+
389
+ _ = ( ^/ ) ( " / " )
390
+
391
+ // MARK: Starting characters
392
+
324
393
// Fine.
325
394
_ = /./
326
395
0 commit comments