diff --git a/Sources/SwiftParser/Statements.swift b/Sources/SwiftParser/Statements.swift index f1c8ecaf382..e761f1c4bd4 100644 --- a/Sources/SwiftParser/Statements.swift +++ b/Sources/SwiftParser/Statements.swift @@ -188,8 +188,8 @@ extension Parser { let condition = self.parseConditionElement(lastBindingKind: elements.last?.condition.as(RawOptionalBindingConditionSyntax.self)?.bindingKeyword) var unexpectedBeforeKeepGoing: RawUnexpectedNodesSyntax? = nil keepGoing = self.consume(if: .comma) - if keepGoing == nil, let andOperator = self.consumeIfContextualPunctuator("&&") { - unexpectedBeforeKeepGoing = RawUnexpectedNodesSyntax(combining: unexpectedBeforeKeepGoing, andOperator, arena: self.arena) + if keepGoing == nil, let token = self.consumeIfContextualPunctuator("&&") ?? self.consume(if: .keyword(.where)) { + unexpectedBeforeKeepGoing = RawUnexpectedNodesSyntax(combining: unexpectedBeforeKeepGoing, token, arena: self.arena) keepGoing = missingToken(.comma) } elements.append( diff --git a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift index 8a5acb476d8..6eb0c8fd1fe 100644 --- a/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift @@ -582,7 +582,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor { if let trailingComma = node.trailingComma { exchangeTokens( unexpected: node.unexpectedBetweenConditionAndTrailingComma, - unexpectedTokenCondition: { $0.text == "&&" }, + unexpectedTokenCondition: { $0.text == "&&" || $0.tokenKind == .keyword(.where) }, correctTokens: [node.trailingComma], message: { _ in .joinConditionsUsingComma }, moveFixIt: { ReplaceTokensFixIt(replaceTokens: $0, replacements: [trailingComma]) } diff --git a/Tests/SwiftParserTest/translated/RecoveryTests.swift b/Tests/SwiftParserTest/translated/RecoveryTests.swift index 05c747f4a3f..ee588bceed0 100644 --- a/Tests/SwiftParserTest/translated/RecoveryTests.swift +++ b/Tests/SwiftParserTest/translated/RecoveryTests.swift @@ -2394,25 +2394,25 @@ final class RecoveryTests: XCTestCase { func testRecovery151() { // QoI: Nonsensical error and fixit if "let" is missing between 'if let ... where' clauses assertParse( - #""" + """ if let y = x 1️⃣where y == 0, let z = x { _ = y _ = z - }2️⃣ - """#, + } + """, diagnostics: [ - // TODO: Old parser expected error on line 4: expected ',' joining parts of a multi-clause condition, Fix-It replacements: 15 - 21 = ',' - DiagnosticSpec(locationMarker: "1️⃣", message: "expected '{' in 'if' statement", fixIts: ["insert '{'"]), - DiagnosticSpec(locationMarker: "1️⃣", message: "unexpected code 'where y == 0,' before variable"), - DiagnosticSpec(locationMarker: "2️⃣", message: "expected '}' to end 'if' statement", fixIts: ["insert '}'"]), + DiagnosticSpec( + message: "expected ',' joining parts of a multi-clause condition", + fixIts: ["replace 'where' with ','"] + ) ], - fixedSource: #""" - if let y = x {where y == 0, let z = x { + fixedSource: """ + if let y = x, y == 0, let z = x { _ = y _ = z } - } - """# + """ + ) }