@@ -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 { ( ) }
@@ -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 4 {{'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,22 @@ 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+ baz ( ^^/ , / ) // expected-error {{missing argument for parameter #2 in call}}
284+ baz ( ( ^^/ ) , / )
285+
245286func bazbaz( _ x: ( Int , Int ) -> Int , _ y: Int ) { }
246287bazbaz ( / , 0 )
288+ bazbaz ( ^^/ , 0 )
247289
248290func qux< T> ( _ x: ( Int , Int ) -> Int , _ y: T ) -> Int { 0 }
249291do {
@@ -257,6 +299,24 @@ do {
257299 // expected-error@-2:21 {{expected ',' separator}}
258300}
259301_ = qux ( / , 1 ) // this comment tests to make sure we don't try and end the regex on the starting '/' of '//'.
302+ _ = qux ( / , 1 ) /* same thing with a block comment */
303+
304+ func quxqux( _ x: ( Int , Int ) -> Int ) { }
305+ quxqux ( /^/ ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
306+ quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
307+ quxqux ( { $0 /^/ $1 } )
308+
309+ quxqux ( !/^/ )
310+ // expected-error@-1 {{cannot convert value of type 'Bool' to expected argument type '(Int, Int) -> Int'}}
311+ // expected-error@-2 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
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