@@ -35,18 +35,23 @@ _ = /x/.self
35
35
_ = /\/ /
36
36
_ = /\\/
37
37
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
+ }
50
55
51
56
_ = / x
52
57
// expected-error@-1 {{unterminated regex literal}}
@@ -58,9 +63,11 @@ _ = (!/x/)
58
63
// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type 'Bool'}}
59
64
60
65
_ = !/ /
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}}
64
71
65
72
_ = !!/ x/
66
73
_ = ( !!/ x/ )
@@ -75,7 +82,6 @@ _ = /x/ + /y/ // expected-error {{binary operator '+' cannot be applied to two '
75
82
_ = /x/ +/ y/
76
83
// expected-error@-1 {{cannot find operator '+/' in scope}}
77
84
// expected-error@-2 {{'/' is not a postfix unary operator}}
78
- // expected-error@-3 {{cannot find 'y' in scope}}
79
85
80
86
_ = /x/ ? . blah
81
87
// 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
102
108
_ = /x/ .../ y/
103
109
// expected-error@-1 {{missing whitespace between '...' and '/' operators}}
104
110
// expected-error@-2 {{'/' is not a postfix unary operator}}
105
- // expected-error@-3 {{cannot find 'y' in scope}}
106
111
107
112
_ = / x / ...
108
113
// 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) {}
120
125
foo ( /abc/ , y: / abc / )
121
126
122
127
func 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}}
129
129
130
130
struct S {
131
131
subscript( x: Regex < Substring > ) -> Void { ( ) }
@@ -259,7 +259,7 @@ _ = /x/*comment*/
259
259
// expected-error@-1 {{unterminated regex literal}}
260
260
261
261
// 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}}
263
263
baz ( / , / )
264
264
// expected-error@-1 {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
265
265
// expected-error@-2 {{missing argument for parameter #2 in call}}
278
278
// expected-note@-2 {{to match this opening '('}}
279
279
} // expected-error {{expected ')' in expression list}}
280
280
281
- // TODO: Should we do prefix operator splitting here?
282
- baz ( ^^/ , / )
281
+ baz ( ^^/ , / ) // expected-error {{missing argument for parameter #2 in call}}
283
282
baz ( ( ^^/ ) , / )
284
283
285
284
func bazbaz( _ x: ( Int , Int ) -> Int , _ y: Int ) { }
@@ -305,8 +304,9 @@ quxqux(/^/) // expected-error {{cannot convert value of type 'Regex<Substring>'
305
304
quxqux ( ( /^/ ) ) // expected-error {{cannot convert value of type 'Regex<Substring>' to expected argument type '(Int, Int) -> Int'}}
306
305
quxqux ( { $0 /^/ $1 } )
307
306
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'}}
310
310
311
311
quxqux ( /^ )
312
312
0 commit comments