File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed
Tests/SwiftParserTest/translated Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -160,11 +160,20 @@ extension Parser {
160
160
let misplacedSpecifiers = parseMisplacedSpecifiers ( )
161
161
162
162
let names = self . parseParameterNames ( )
163
- let colon = self . consume ( if: . colon)
164
- let type : RawTypeSyntax ?
165
- if colon != nil {
166
- type = self . parseType ( misplacedSpecifiers: misplacedSpecifiers)
167
- } else {
163
+ var colon = self . consume ( if: . colon)
164
+ // try to parse the type regardless of the presence of the preceding colon
165
+ // because the parameter may be unnamed
166
+ // e.g. { [X] in } or { (:[X]) in }
167
+ var type : RawTypeSyntax ? = self . parseType ( misplacedSpecifiers: misplacedSpecifiers)
168
+ if type? . raw. kind != . missingType {
169
+ if colon == nil {
170
+ // mark the preceding colon as missing if the parameter is unnamed
171
+ // e.g. { [X] in }
172
+ colon = missingToken ( . colon)
173
+ }
174
+ } else if colon == nil {
175
+ // don't mark the type as missing if the preceding colon is absent
176
+ // e.g. { _ in }
168
177
type = nil
169
178
}
170
179
Original file line number Diff line number Diff line change @@ -3355,4 +3355,19 @@ final class RecoveryTests: ParserTestCase {
3355
3355
]
3356
3356
)
3357
3357
}
3358
+
3359
+ func testRecovery185( ) {
3360
+ // <rdar://1181099123>
3361
+ assertParse (
3362
+ """
3363
+ test { (1️⃣[X]) in }
3364
+ """ ,
3365
+ diagnostics: [
3366
+ DiagnosticSpec ( message: " expected identifier and ':' in parameter " , fixIts: [ " insert identifier and ':' " ] ) ,
3367
+ ] ,
3368
+ fixedSource: """
3369
+ test { (<#identifier#>: [X]) in }
3370
+ """
3371
+ )
3372
+ }
3358
3373
}
You can’t perform that action at this time.
0 commit comments