@@ -6,13 +6,26 @@ prefix operator / // expected-error {{prefix operator may not contain '/'}}
66prefix operator ^/ // expected-error {{prefix operator may not contain '/'}}
77prefix operator /^/ // expected-error {{prefix operator may not contain '/'}}
88
9+ prefix operator !!
10+ prefix func !! < T> ( _ x: T ) -> T { x }
11+
12+ prefix operator ^^
13+ prefix func ^^ < T> ( _ x: T ) -> T { x }
14+
915precedencegroup P {
1016 associativity : left
1117}
1218
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.
1421infix 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 }
1629
1730let i = 0 /^/ 1 /^/ 3
1831
@@ -41,6 +54,21 @@ _ = /x
4154_ = !/ x/
4255// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
4356
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+
4472_ = /x/ ! // expected-error {{cannot force unwrap value of non-optional type 'Regex<Substring>'}}
4573_ = /x/ + /y/ // expected-error {{binary operator '+' cannot be applied to two 'Regex<Substring>' operands}}
4674
@@ -231,7 +259,7 @@ _ = /x/*comment*/
231259// expected-error@-1 {{unterminated regex literal}}
232260
233261// These become regex literals, unless surrounded in parens.
234- func baz( _ x: ( Int, Int) - > Int, _ y: ( Int, Int) - > Int) { } // expected-note 2 {{'baz' declared here}}
262+ func baz( _ x: ( Int, Int) - > Int, _ y: ( Int, Int) - > Int) { } // expected-note 3 {{'baz' declared here}}
235263baz ( / , / )
236264// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
237265// expected-error@-2 {{missing argument for parameter #2 in call}}
@@ -240,8 +268,23 @@ baz(/,/)
240268// expected-error@-2 {{missing argument for parameter #2 in call}}
241269baz ( ( / ) , / )
242270
271+ baz ( /^ , / )
272+ // expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
273+ // expected-error@-2 {{missing argument for parameter #2 in call}}
274+
275+ do {
276+ baz ( ( /^ ) , / )
277+ // expected-error@-1 {{closing ')' does not balance any groups openings}}
278+ // expected-note@-2 {{to match this opening '('}}
279+ } // expected-error {{expected ')' in expression list}}
280+
281+ // TODO: Should we do prefix operator splitting here?
282+ baz ( ^^/ , / )
283+ baz ( ( ^^/ ) , / )
284+
243285func bazbaz( _ x: ( Int , Int ) -> Int , _ y: Int ) { }
244286bazbaz ( / , 0 )
287+ bazbaz ( ^^/ , 0 )
245288
246289func qux< T> ( _ x: ( Int , Int ) -> Int , _ y: T ) -> Int { 0 }
247290do {
@@ -255,6 +298,23 @@ do {
255298 // expected-error@-2:21 {{expected ',' separator}}
256299}
257300_ = qux ( / , 1 ) // this comment tests to make sure we don't try and end the regex on the starting '/' of '//'.
301+ _ = qux ( / , 1 ) /* same thing with a block comment */
302+
303+ func quxqux( _ x: ( Int , Int ) -> Int ) { }
304+ quxqux ( /^/ ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
305+ quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
306+ quxqux ( { $0 /^/ $1 } )
307+
308+ // FIXME: We should be able to do operator splitting here and form `!(/^/)`.
309+ quxqux ( !/^/ ) // expected-error {{unary operators must not be juxtaposed; parenthesize inner expression}}
310+
311+ quxqux ( /^ )
312+
313+ do {
314+ quxqux ( /^ ) / 1
315+ // expected-error@-1 {{closing ')' does not balance any groups openings}}
316+ // expected-error@-2 {{expected ',' separator}}
317+ }
258318
259319let arr : [ Double ] = [ 2 , 3 , 4 ]
260320_ = arr. reduce ( 1 , / ) / 3
@@ -282,3 +342,15 @@ _ = /0oG/
282342_ = /"/
283343_ = /'/
284344_ = / < #placeholder#>/
345+
346+ _ = ^^/ 0 xG/
347+ _ = ^^/ 0 oG/
348+ _ = ^^/ " /
349+ _ = ^^/'/
350+ _ = ^^/<#placeholder#>/
351+
352+ _ = (^^/0xG/)
353+ _ = (^^/0oG/)
354+ _ = (^^/ " / )
355+ _ = ( ^^/ '/ )
356+ _ = ( ^^/ < #placeholder#>/ )
0 commit comments