@@ -35,18 +35,23 @@ _ = /x/.self
3535_ = /\/ /
3636_ = /\\/
3737
38- // These unfortunately become infix `=/`. We could likely improve the diagnostic
39- // though.
40- let z =/ 0 /
41- // expected-error@-1 {{type annotation missing in pattern}}
42- // expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
43- // expected-error@-3 {{expected expression after unary operator}}
44- // expected-error@-4 {{cannot find operator '=/' in scope}}
45- // expected-error@-5 {{'/' is not a postfix unary operator}}
46- _=/ 0 /
47- // expected-error@-1 {{'_' can only appear in a pattern or on the left side of an assignment}}
48- // expected-error@-2 {{cannot find operator '=/' in scope}}
49- // 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+ }
5055
5156_ = / x
5257// expected-error@-1 {{unterminated regex literal}}
@@ -58,9 +63,11 @@ _ = (!/x/)
5863// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
5964
6065_ = !/ /
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}}
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}}
6471
6572_ = !!/ x/
6673_ = ( !!/ x/ )
@@ -75,7 +82,6 @@ _ = /x/ + /y/ // expected-error {{binary operator '+' cannot be applied to two '
7582_ = /x/ +/ y/
7683// expected-error@-1 {{cannot find operator '+/' in scope}}
7784// expected-error@-2 {{'/' is not a postfix unary operator}}
78- // expected-error@-3 {{cannot find 'y' in scope}}
7985
8086_ = /x/ ? . blah
8187// expected-error@-1 {{cannot use optional chaining on non-optional value of type 'Regex<Substring>'}}
@@ -102,7 +108,6 @@ _ = /x/ ... /y/ // expected-error {{referencing operator function '...' on 'Comp
102108_ = /x/ .../ y/
103109// expected-error@-1 {{missing whitespace between '...' and '/' operators}}
104110// expected-error@-2 {{'/' is not a postfix unary operator}}
105- // expected-error@-3 {{cannot find 'y' in scope}}
106111
107112_ = / x / ...
108113// expected-error@-1 {{unary operator '...' cannot be applied to an operand of type 'Regex<Substring>'}}
@@ -120,12 +125,7 @@ func foo<T>(_ x: T, y: T) {}
120125foo ( /abc/ , y: / abc / )
121126
122127func bar< T> ( _ x: inout T ) { }
123-
124- // TODO: We split this into a prefix '&', but inout is handled specially when
125- // parsing an argument list. This shouldn't matter anyway, but we should at
126- // least have a custom diagnostic.
127- bar ( &/ x/ )
128- // 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}}
129129
130130struct S {
131131 subscript( x: Regex < Substring > ) -> Void { ( ) }
@@ -259,7 +259,7 @@ _ = /x/*comment*/
259259// expected-error@-1 {{unterminated regex literal}}
260260
261261// These become regex literals, unless surrounded in parens.
262- func baz( _ x: ( Int, Int) - > Int, _ y: ( Int, Int) - > Int) { } // expected-note 3 {{'baz' declared here}}
262+ func baz( _ x: ( Int, Int) - > Int, _ y: ( Int, Int) - > Int) { } // expected-note 4 {{'baz' declared here}}
263263baz ( / , / )
264264// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
265265// expected-error@-2 {{missing argument for parameter #2 in call}}
278278 // expected-note@-2 {{to match this opening '('}}
279279} // expected-error {{expected ')' in expression list}}
280280
281- // TODO: Should we do prefix operator splitting here?
282- baz ( ^^/ , / )
281+ baz ( ^^/ , / ) // expected-error {{missing argument for parameter #2 in call}}
283282baz ( ( ^^/ ) , / )
284283
285284func bazbaz( _ x: ( Int , Int ) -> Int , _ y: Int ) { }
@@ -305,8 +304,9 @@ quxqux(/^/) // expected-error {{cannot convert value of type 'Regex<Substring>'
305304quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
306305quxqux ( { $0 /^/ $1 } )
307306
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}}
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'}}
310310
311311quxqux ( /^ )
312312
0 commit comments