@@ -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
@@ -22,32 +35,53 @@ _ = /x/.self
2235_ = /\/ /
2336_ = /\\/
2437
25- // These unfortunately become infix `=/`. We could likely improve the diagnostic
26- // though.
27- let z =/ 0 /
28- // expected-error@-1 {{type annotation missing in pattern}}
29- // expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
30- // expected-error@-3 {{expected expression after unary operator}}
31- // expected-error@-4 {{cannot find operator '=/' in scope}}
32- // expected-error@-5 {{'/' is not a postfix unary operator}}
33- _=/ 0 /
34- // expected-error@-1 {{'_' can only appear in a pattern or on the left side of an assignment}}
35- // expected-error@-2 {{cannot find operator '=/' in scope}}
36- // expected-error@-3 {{'/' is not a postfix unary operator}}
38+ // This is just here to appease typo correction.
39+ let y = 0
40+
41+ // These unfortunately become prefix `=` and infix `=/` respectively. We could
42+ // likely improve the diagnostic though.
43+ do {
44+ let z =/0 /
45+ // expected-error@-1 {{type annotation missing in pattern}}
46+ // expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
47+ // expected-error@-3 {{expected expression}}
48+ }
49+ do {
50+ _=/ 0 /
51+ // expected-error@-1 {{'_' can only appear in a pattern or on the left side of an assignment}}
52+ // expected-error@-2 {{cannot find operator '=/' in scope}}
53+ // expected-error@-3 {{'/' is not a postfix unary operator}}
54+ }
3755
3856_ = / x
3957// expected-error@-1 {{unterminated regex literal}}
4058
4159_ = !/ x/
4260// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
4361
62+ _ = ( !/ x/ )
63+ // expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
64+
65+ _ = !/ /
66+ // expected-error@-1 {{regex literal may not start with space; add backslash to escape}}
67+ // expected-error@-2 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
68+
69+ _ = !!/ /
70+ // expected-error@-1 {{regex literal may not start with space; add backslash to escape}}
71+
72+ _ = !!/ x/
73+ _ = ( !!/ x/ )
74+
75+ _ = /^ )
76+ // expected-error@-1 {{unterminated regex literal}}
77+ // expected-error@-2 {{closing ')' does not balance any groups openings}}
78+
4479_ = /x/ ! // expected-error {{cannot force unwrap value of non-optional type 'Regex<Substring>'}}
4580_ = /x/ + /y/ // expected-error {{binary operator '+' cannot be applied to two 'Regex<Substring>' operands}}
4681
4782_ = /x/ +/ y/
4883// expected-error@-1 {{cannot find operator '+/' in scope}}
4984// expected-error@-2 {{'/' is not a postfix unary operator}}
50- // expected-error@-3 {{cannot find 'y' in scope}}
5185
5286_ = /x/ ? . blah
5387// expected-error@-1 {{cannot use optional chaining on non-optional value of type 'Regex<Substring>'}}
@@ -74,7 +108,6 @@ _ = /x/ ... /y/ // expected-error {{referencing operator function '...' on 'Comp
74108_ = /x/ .../ y/
75109// expected-error@-1 {{missing whitespace between '...' and '/' operators}}
76110// expected-error@-2 {{'/' is not a postfix unary operator}}
77- // expected-error@-3 {{cannot find 'y' in scope}}
78111
79112_ = / x / ...
80113// expected-error@-1 {{unary operator '...' cannot be applied to an operand of type 'Regex<Substring>'}}
@@ -92,12 +125,7 @@ func foo<T>(_ x: T, y: T) {}
92125foo ( /abc/ , y: / abc / )
93126
94127func bar< T> ( _ x: inout T ) { }
95-
96- // TODO: We split this into a prefix '&', but inout is handled specially when
97- // parsing an argument list. This shouldn't matter anyway, but we should at
98- // least have a custom diagnostic.
99- bar ( &/ x/ )
100- // expected-error@-1 {{'&' is not a prefix unary operator}}
128+ bar ( &/ x/ ) // expected-error {{cannot pass immutable value as inout argument: literals are not mutable}}
101129
102130struct S {
103131 subscript( x: Regex < Substring > ) -> Void { ( ) }
@@ -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 4 {{'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,22 @@ 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+ baz ( ^^/ , / ) // expected-error {{missing argument for parameter #2 in call}}
282+ baz ( ( ^^/ ) , / )
283+
243284func bazbaz( _ x: ( Int , Int ) -> Int , _ y: Int ) { }
244285bazbaz ( / , 0 )
286+ bazbaz ( ^^/ , 0 )
245287
246288func qux< T> ( _ x: ( Int , Int ) -> Int , _ y: T ) -> Int { 0 }
247289do {
@@ -255,6 +297,24 @@ do {
255297 // expected-error@-2:21 {{expected ',' separator}}
256298}
257299_ = qux ( / , 1 ) // this comment tests to make sure we don't try and end the regex on the starting '/' of '//'.
300+ _ = qux ( / , 1 ) /* same thing with a block comment */
301+
302+ func quxqux( _ x: ( Int , Int ) -> Int ) { }
303+ quxqux ( /^/ ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
304+ quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
305+ quxqux ( { $0 /^/ $1 } )
306+
307+ quxqux ( !/^/ )
308+ // expected-error@-1 {{cannot convert value of type 'Bool' to expected argument type '(Int, Int) -> Int'}}
309+ // expected-error@-2 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
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