@@ -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
@@ -233,7 +261,7 @@ _ = /x/*comment*/
233261// expected-error@-1 {{unterminated regex literal}}
234262
235263// 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}}
237265baz ( / , / )
238266// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
239267// expected-error@-2 {{missing argument for parameter #2 in call}}
@@ -242,8 +270,23 @@ baz(/,/)
242270// expected-error@-2 {{missing argument for parameter #2 in call}}
243271baz ( ( / ) , / )
244272
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+
245287func bazbaz( _ x: ( Int , Int ) -> Int , _ y: Int ) { }
246288bazbaz ( / , 0 )
289+ bazbaz ( ^^/ , 0 )
247290
248291func qux< T> ( _ x: ( Int , Int ) -> Int , _ y: T ) -> Int { 0 }
249292do {
@@ -257,6 +300,23 @@ do {
257300 // expected-error@-2:21 {{expected ',' separator}}
258301}
259302_ = 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+ }
260320
261321let arr : [ Double ] = [ 2 , 3 , 4 ]
262322_ = arr. reduce ( 1 , / ) / 3
@@ -284,3 +344,15 @@ _ = /0oG/
284344_ = /"/
285345_ = /'/
286346_ = / < #placeholder#>/
347+
348+ _ = ^^/ 0 xG/
349+ _ = ^^/ 0 oG/
350+ _ = ^^/ " /
351+ _ = ^^/'/
352+ _ = ^^/<#placeholder#>/
353+
354+ _ = (^^/0xG/)
355+ _ = (^^/0oG/)
356+ _ = (^^/ " / )
357+ _ = ( ^^/ '/ )
358+ _ = ( ^^/ < #placeholder#>/ )
0 commit comments