Skip to content

Commit a920e3c

Browse files
committed
Add diagnostic for unexpected second identifier
1 parent 5594b98 commit a920e3c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,19 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
810810
return .visitChildren
811811
}
812812

813+
public override func visit(_ node: PatternBindingSyntax) -> SyntaxVisitorContinueKind {
814+
if shouldSkip(node) {
815+
return .skipChildren
816+
}
817+
818+
if let unexpected = (node.pattern.as(TuplePatternSyntax.self)?.unexpectedBetweenElementsAndRightParen),
819+
let previousToken = node.previousToken(viewMode: .sourceAccurate) {
820+
addDiagnostic(unexpected, SpaceSeparatedIdentifiersError(firstToken: previousToken, additionalTokens: []))
821+
}
822+
823+
return .visitChildren
824+
}
825+
813826
public override func visit(_ node: PrecedenceGroupAssignmentSyntax) -> SyntaxVisitorContinueKind {
814827
if shouldSkip(node) {
815828
return .skipChildren

Tests/SwiftParserTest/translated/RecoveryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ final class RecoveryTests: XCTestCase {
828828
""",
829829
diagnostics: [
830830
// TODO: (good first issue) Old parser expected error on line 1: found an unexpected second identifier in constant declaration; is there an accidental break?
831-
DiagnosticSpec(message: "unexpected code 'hij, foobar' in tuple pattern")
831+
DiagnosticSpec(message: "found an unexpected second identifier in variable")
832832
]
833833
)
834834
}

0 commit comments

Comments
 (0)