@@ -6,6 +6,8 @@ prefix operator /
66prefix operator ^/
77prefix operator /^/
88
9+ prefix func ^/ < T> ( _ x: T ) -> T { x } // expected-note {{'^/' declared here}}
10+
911prefix operator !!
1012prefix func !! < T> ( _ x: T ) -> T { x }
1113
@@ -259,6 +261,8 @@ _ = /x // comment
259261_ = /x/ * comment*/
260262// expected-error@-1 {{'/' is not a prefix unary operator}}
261263
264+ // MARK: Unapplied operators
265+
262266// These become regex literals, unless surrounded in parens.
263267func baz( _ x: ( Int, Int) - > Int, _ y: ( Int, Int) - > Int) { } // expected-note 4{{'baz' declared here}}
264268baz ( / , / )
@@ -273,11 +277,7 @@ baz(/^, /)
273277// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
274278// expected-error@-2 {{missing argument for parameter #2 in call}}
275279
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 ( ( /^ ) , / )
281281
282282baz ( ^^/ , / ) // expected-error {{missing argument for parameter #2 in call}}
283283baz ( ( ^^/ ) , / )
@@ -287,20 +287,18 @@ bazbaz(/, 0)
287287bazbaz ( ^^/ , 0 )
288288
289289func 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
295291do {
296292 _ = qux ( / , " ( " ) / 2
297293 // expected-error@-1 {{cannot convert value of type 'Regex<(Substring, Substring)>' to expected argument type '(Int, Int) -> Int'}}
298294 // expected-error@-2:21 {{expected ',' separator}}
299295}
296+ _ = qux ( ( / ) , " ( " ) / 2
300297_ = qux ( / , 1 ) // this comment tests to make sure we don't try and end the regex on the starting '/' of '//'.
301298_ = qux ( / , 1 ) /* same thing with a block comment */
302299
303- func quxqux( _ x: ( Int , Int ) -> Int ) { }
300+ @discardableResult
301+ func quxqux( _ x: ( Int , Int ) -> Int ) -> Int { 0 }
304302quxqux ( /^/ ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
305303quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
306304quxqux ( { $0 /^/ $1 } )
@@ -310,17 +308,88 @@ quxqux(!/^/)
310308// expected-error@-2 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
311309
312310quxqux ( /^ )
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
319312
320313let arr : [ Double ] = [ 2 , 3 , 4 ]
321314_ = arr. reduce ( 1 , / ) / 3
322315_ = arr. reduce ( 1 , / ) + arr. reduce ( 1 , / )
323316
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+
324393// Fine.
325394_ = /./
326395
0 commit comments