2
2
3
3
import XCTest
4
4
5
+ // https://github.com/apple/swift/issues/44070
5
6
final class DiagnoseInitializerAsTypedPatternTests : XCTestCase {
6
- func testDiagnoseInitializerAsTypedPattern1 ( ) {
7
+ func testDiagnoseInitializerAsTypedPattern3a ( ) {
7
8
AssertParse (
8
9
"""
9
- // https://github.com/apple/swift/issues/44070
10
- """
10
+ let a1️⃣:[X]()
11
+ """ ,
12
+ diagnostics: [
13
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
14
+ ] , fixedSource: " let a=[X]() "
11
15
)
12
16
}
13
17
14
- func testDiagnoseInitializerAsTypedPattern2 ( ) {
18
+ func testDiagnoseInitializerAsTypedPattern3b ( ) {
15
19
AssertParse (
16
20
"""
17
- class X {}
18
- func foo() {}
21
+ let b1️⃣: [X]()
22
+ """ ,
23
+ diagnostics: [
24
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
25
+ ] , fixedSource: " let b= [X]() "
26
+ )
27
+ }
28
+
29
+ func testDiagnoseInitializerAsTypedPattern3c( ) {
30
+ AssertParse (
19
31
"""
32
+ let c 1️⃣:[X]()
33
+ """ ,
34
+ diagnostics: [
35
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
36
+ ] , fixedSource: " let c =[X]() "
20
37
)
21
38
}
22
39
23
- func testDiagnoseInitializerAsTypedPattern3 ( ) {
40
+ func testDiagnoseInitializerAsTypedPattern3d ( ) {
24
41
AssertParse (
25
42
"""
26
- let a:[X]1️⃣()
27
- let b: [X]2️⃣()
28
- let c :[X]3️⃣()
29
- let d : [X]4️⃣()
43
+ let d 1️⃣: [X]()
30
44
""" ,
31
45
diagnostics: [
32
- // TODO: Old parser expected error on line 1: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' = '
33
- DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
34
- // TODO: Old parser expected error on line 2: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' ='
35
- DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
36
- // TODO: Old parser expected error on line 3: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 7 - 8 = '= '
37
- DiagnosticSpec ( locationMarker: " 3️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
38
- // TODO: Old parser expected error on line 4: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 7 - 8 = '='
39
- DiagnosticSpec ( locationMarker: " 4️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
40
- ]
46
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
47
+ ] , fixedSource: " let d = [X]() "
41
48
)
42
49
}
43
50
51
+
44
52
func testDiagnoseInitializerAsTypedPattern4( ) {
45
53
AssertParse (
46
54
"""
47
- let e: X1️⃣()2️⃣ , ee: Int
55
+ let e1️⃣: X() , ee: Int
48
56
""" ,
49
57
diagnostics: [
50
- // TODO: Old parser expected error on line 1: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' ='
51
- DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
52
- DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " extraneous code ', ee: Int' at top level " ) ,
53
- ]
58
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " ) ,
59
+ ] , fixedSource: " let e= X(), ee: Int "
54
60
)
55
61
}
56
62
57
63
func testDiagnoseInitializerAsTypedPattern5( ) {
58
64
AssertParse (
59
65
"""
60
- let f :/*comment*/[X]1️⃣ ()
66
+ let f1️⃣ :/*comment*/[X]()
61
67
""" ,
62
68
diagnostics: [
63
- // TODO: Old parser expected error on line 1: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' = '
64
- DiagnosticSpec ( message: " consecutive statements on a line must be separated by ';' " )
65
- ]
69
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
70
+ ] , fixedSource: " let f=/*comment*/[X]() "
66
71
)
67
72
}
68
73
@@ -75,9 +80,9 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
75
80
}
76
81
77
82
func testDiagnoseInitializerAsTypedPattern7( ) {
83
+ // paren follows the type, but it's part of a separate (valid) expression
78
84
AssertParse (
79
85
"""
80
- // paren follows the type, but it's part of a separate (valid) expression
81
86
let ff: X
82
87
(_1, _2) = (_2, _1)
83
88
let fff: X
@@ -86,52 +91,121 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
86
91
)
87
92
}
88
93
89
- func testDiagnoseInitializerAsTypedPattern8( ) {
94
+ func testDiagnoseInitializerAsTypedPattern8a( ) {
95
+ AssertParse (
96
+ """
97
+ let g1️⃣: X(x)
98
+ """ ,
99
+ diagnostics: [
100
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
101
+ ]
102
+ )
103
+ }
104
+
105
+ func testDiagnoseInitializerAsTypedPattern8b( ) {
106
+ AssertParse (
107
+ """
108
+ let h1️⃣: X(x, y)
109
+ """ ,
110
+ diagnostics: [
111
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
112
+ ]
113
+ )
114
+ }
115
+
116
+ func testDiagnoseInitializerAsTypedPattern8c( ) {
117
+ AssertParse (
118
+ """
119
+ let i1️⃣: X() { foo() }
120
+ """ ,
121
+ diagnostics: [
122
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
123
+ ]
124
+ )
125
+ }
126
+
127
+ func testDiagnoseInitializerAsTypedPattern8d( ) {
90
128
AssertParse (
91
129
"""
92
- let g: X1️⃣(x)
93
- let h: X2️⃣(x, y)
94
- let i: X3️⃣() { foo() }
95
- let j: X4️⃣(x) { foo() }
96
- let k: X5️⃣(x, y) { foo() }
130
+ let j1️⃣: X(x) { foo() }
97
131
""" ,
98
132
diagnostics: [
99
- // TODO: Old parser expected error on line 1: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' ='
100
- DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
101
- // TODO: Old parser expected error on line 2: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' ='
102
- DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
103
- // TODO: Old parser expected error on line 3: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' ='
104
- DiagnosticSpec ( locationMarker: " 3️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
105
- // TODO: Old parser expected error on line 4: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' ='
106
- DiagnosticSpec ( locationMarker: " 4️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
107
- // TODO: Old parser expected error on line 5: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 6 - 7 = ' ='
108
- DiagnosticSpec ( locationMarker: " 5️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
133
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
109
134
]
110
135
)
111
136
}
112
137
113
- func testDiagnoseInitializerAsTypedPattern9( ) {
138
+ func testDiagnoseInitializerAsTypedPattern8e( ) {
139
+ AssertParse (
140
+ """
141
+ let k1️⃣: X(x, y) { foo() }
142
+ """ ,
143
+ diagnostics: [
144
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
145
+ ]
146
+ )
147
+ }
148
+
149
+ func testDiagnoseInitializerAsTypedPattern9a( ) {
114
150
AssertParse (
115
151
"""
116
152
func nonTopLevel() {
117
- let a:[X]1️⃣()
118
- let i: X2️⃣() { foo() }
119
- let j: X3️⃣(x) { foo() }
120
- let k: X4️⃣(x, y) { foo() }
121
- _ = (a, i, j, k)
153
+ let a1️⃣:[X]()
154
+ }
155
+ """ ,
156
+ diagnostics: [
157
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
158
+ ]
159
+ )
160
+ }
161
+
162
+ func testDiagnoseInitializerAsTypedPattern9b( ) {
163
+ AssertParse (
164
+ """
165
+ func nonTopLevel() {
166
+ let i1️⃣: X() { foo() }
122
167
}
123
168
""" ,
124
169
diagnostics: [
125
- // TODO: Old parser expected error on line 2: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 8 - 9 = ' = '
126
- DiagnosticSpec ( locationMarker: " 1️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
127
- // TODO: Old parser expected error on line 3: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 8 - 9 = ' ='
128
- DiagnosticSpec ( locationMarker: " 2️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
129
- // TODO: Old parser expected error on line 4: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 8 - 9 = ' ='
130
- DiagnosticSpec ( locationMarker: " 3️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
131
- // TODO: Old parser expected error on line 5: unexpected initializer in pattern; did you mean to use '='?, Fix-It replacements: 8 - 9 = ' ='
132
- DiagnosticSpec ( locationMarker: " 4️⃣ " , message: " consecutive statements on a line must be separated by ';' " ) ,
170
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
133
171
]
134
172
)
135
173
}
136
174
175
+ func testDiagnoseInitializerAsTypedPattern9c( ) {
176
+ AssertParse (
177
+ """
178
+ func nonTopLevel() {
179
+ let j1️⃣: X(x) { foo() }
180
+ }
181
+ """ ,
182
+ diagnostics: [
183
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
184
+ ]
185
+ )
186
+ }
187
+
188
+ func testDiagnoseInitializerAsTypedPattern9d( ) {
189
+ AssertParse (
190
+ """
191
+ func nonTopLevel() {
192
+ let k1️⃣: X(x, y) { foo() }
193
+ }
194
+ """ ,
195
+ diagnostics: [
196
+ DiagnosticSpec ( message: " unexpected initializer in pattern; did you mean to use '='? " , fixIts: [ " replace ':' by '=' " ] ) ,
197
+ ]
198
+ )
199
+ }
200
+
201
+ func testDiagnoseInitializerAsTypedPattern9e( ) {
202
+ AssertParse (
203
+ """
204
+ func nonTopLevel() {
205
+ _ = (a, i, j, k)
206
+ }
207
+ """
208
+ )
209
+ }
210
+
137
211
}
0 commit comments