Skip to content

Commit 9a20d2f

Browse files
committed
Remove "after <previous token>" clause from missing node diagnostics
1 parent a4d8510 commit 9a20d2f

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

Sources/SwiftParser/Diagnostics/ParserDiagnosticMessages.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ public struct MissingNodesError: ParserError {
238238
return "after '\(lastModifier.name.text)' modifier"
239239
} else if let missingDecl = missingNodes.first?.as(MissingDeclSyntax.self), missingDecl.attributes != nil {
240240
return "after attribute"
241-
} else if let previousToken = missingNodes.first?.previousToken(viewMode: .fixedUp), previousToken.presence == .present {
242-
return "after '\(previousToken.text)'"
243241
}
244242
}
245243
return nil

Tests/SwiftParserTest/Declarations.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ final class DeclarationTests: XCTestCase {
702702
}
703703
""",
704704
diagnostics: [
705-
DiagnosticSpec(locationMarker: "EXPECTED_DECL", message: "Expected declaration after '{' in struct"),
705+
DiagnosticSpec(locationMarker: "EXPECTED_DECL", message: "Expected declaration in struct"),
706706
DiagnosticSpec(locationMarker: "UNEXPECTED_TEXT", message: #"Unexpected text '/ ###line 25 "line-directive.swift"' in struct"#)
707707
]
708708
)
@@ -893,9 +893,9 @@ final class DeclarationTests: XCTestCase {
893893
""",
894894
diagnostics: [
895895
DiagnosticSpec(locationMarker: "OPENING_BRACE", message: "Expected '{' to start struct"),
896-
DiagnosticSpec(locationMarker: "AFTER_POUND_IF", message: "Expected condition after '#if' in conditional compilation clause"),
896+
DiagnosticSpec(locationMarker: "AFTER_POUND_IF", message: "Expected condition in conditional compilation clause"),
897897
DiagnosticSpec(locationMarker: "END", message: "Expected declaration after attribute in conditional compilation clause"),
898-
DiagnosticSpec(locationMarker: "END", message: "Expected name after '@' in attribute"),
898+
DiagnosticSpec(locationMarker: "END", message: "Expected name in attribute"),
899899
DiagnosticSpec(locationMarker: "END", message: "Expected '#endif' in conditional compilation block"),
900900
DiagnosticSpec(locationMarker: "END", message: "Expected '}' to end struct")
901901
]

Tests/SwiftParserTest/Expressions.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ final class ExpressionTests: XCTestCase {
77
AssertParse(
88
"let a =#^DIAG^#",
99
diagnostics: [
10-
DiagnosticSpec(message: "Expected expression after '=' in variable")
10+
DiagnosticSpec(message: "Expected expression in variable")
1111
]
1212
)
1313

1414
AssertParse("a ? b : c ? d : e")
1515
AssertParse(
1616
"a ? b :#^DIAG^#",
1717
diagnostics: [
18-
DiagnosticSpec(message: "Expected expression after ':'")
18+
DiagnosticSpec(message: "Expected expression")
1919
]
2020
)
2121
}
@@ -102,7 +102,7 @@ final class ExpressionTests: XCTestCase {
102102
c[#^DIAG^#
103103
"""#,
104104
diagnostics: [
105-
DiagnosticSpec(message: "Expected value after '[' in subscript"),
105+
DiagnosticSpec(message: "Expected value in subscript"),
106106
DiagnosticSpec(message: "Expected ']' to end subscript"),
107107
]
108108
)
@@ -167,7 +167,7 @@ final class ExpressionTests: XCTestCase {
167167
,#^END_ARRAY^#
168168
""",
169169
diagnostics: [
170-
DiagnosticSpec(locationMarker: "EXPECTED_EXPR", message: "Expected value after '[' in array element"),
170+
DiagnosticSpec(locationMarker: "EXPECTED_EXPR", message: "Expected value in array element"),
171171
DiagnosticSpec(locationMarker: "END_ARRAY", message: "Expected ']' to end array"),
172172
]
173173
)
@@ -177,7 +177,7 @@ final class ExpressionTests: XCTestCase {
177177
([1:#^DIAG^#)
178178
""",
179179
diagnostics: [
180-
DiagnosticSpec(message: "Expected value after ':' in dictionary element"),
180+
DiagnosticSpec(message: "Expected value in dictionary element"),
181181
DiagnosticSpec(message: "Expected ']' to end dictionary"),
182182
]
183183
)
@@ -395,8 +395,8 @@ final class ExpressionTests: XCTestCase {
395395
\#^AFTER_SLASH^#\(#^AFTER_PAREN^#
396396
"""##,
397397
diagnostics: [
398-
DiagnosticSpec(locationMarker: "AFTER_SLASH", message: #"Expected root and expression after '\' in key path"#),
399-
DiagnosticSpec(locationMarker: "AFTER_PAREN", message: "Expected value after '(' in tuple"),
398+
DiagnosticSpec(locationMarker: "AFTER_SLASH", message: #"Expected root and expression in key path"#),
399+
DiagnosticSpec(locationMarker: "AFTER_PAREN", message: "Expected value in tuple"),
400400
DiagnosticSpec(locationMarker: "AFTER_PAREN", message: "Expected ')' to end tuple"),
401401
DiagnosticSpec(locationMarker: "AFTER_PAREN", message: "Expected expression in key path"),
402402
]
@@ -455,8 +455,8 @@ final class ExpressionTests: XCTestCase {
455455
print "\(i)\"\n#^END^#
456456
"""#,
457457
diagnostics: [
458-
DiagnosticSpec(locationMarker: "KEY_PATH_1", message: "Expected expression after 'n' in key path"),
459-
DiagnosticSpec(locationMarker: "KEY_PATH_2", message: "Expected expression after 'n' in key path"),
458+
DiagnosticSpec(locationMarker: "KEY_PATH_1", message: "Expected expression in key path"),
459+
DiagnosticSpec(locationMarker: "KEY_PATH_2", message: "Expected expression in key path"),
460460
DiagnosticSpec(locationMarker: "END", message: #"Expected '"' in string literal"#),
461461
DiagnosticSpec(locationMarker: "END", message: "Expected '}' to end 'if' statement"),
462462
DiagnosticSpec(locationMarker: "END", message: "Expected '}' to end function"),
@@ -467,7 +467,7 @@ final class ExpressionTests: XCTestCase {
467467
diagnostics: [
468468
DiagnosticSpec(message: "Expected identifier in '#keyPath' expression"),
469469
DiagnosticSpec(message: "Expected ')' to end '#keyPath' expression"),
470-
DiagnosticSpec(locationMarker: "MISSING_VALUE", message: "Expected value after ':' in function call"),
470+
DiagnosticSpec(locationMarker: "MISSING_VALUE", message: "Expected value in function call"),
471471
])
472472
}
473473

@@ -476,7 +476,7 @@ final class ExpressionTests: XCTestCase {
476476
"[(Int) -> #^DIAG^#throws Int]()",
477477
diagnostics: [
478478
// FIXME: We should suggest to move 'throws' in front of '->'
479-
DiagnosticSpec(message: "Expected expression after '->' in array element"),
479+
DiagnosticSpec(message: "Expected expression in array element"),
480480
DiagnosticSpec(message: "Unexpected text 'throws Int' in array"),
481481
]
482482
)
@@ -498,7 +498,7 @@ final class ExpressionTests: XCTestCase {
498498
}
499499
""",
500500
diagnostics: [
501-
DiagnosticSpec(message: "Expected expression after ':' in 'do' statement")
501+
DiagnosticSpec(message: "Expected expression in 'do' statement")
502502
]
503503
)
504504
}
@@ -509,10 +509,10 @@ final class ExpressionTests: XCTestCase {
509509
let #^VAR_NAME^#:(#^DIAG_1^#..)->#^END^#
510510
""",
511511
diagnostics: [
512-
DiagnosticSpec(locationMarker: "VAR_NAME", message: "Expected pattern after 'let' in variable"),
513-
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected type after '(' in function type"),
512+
DiagnosticSpec(locationMarker: "VAR_NAME", message: "Expected pattern in variable"),
513+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected type in function type"),
514514
DiagnosticSpec(locationMarker: "DIAG_1", message: "Unexpected text '..' in function type"),
515-
DiagnosticSpec(locationMarker: "END", message: "Expected type after '->' in function type"),
515+
DiagnosticSpec(locationMarker: "END", message: "Expected type in function type"),
516516
]
517517
)
518518
}
@@ -524,7 +524,7 @@ final class ExpressionTests: XCTestCase {
524524
substructure: Syntax(TokenSyntax.contextualKeyword("async")),
525525
substructureAfterMarker: "ASYNC",
526526
diagnostics: [
527-
DiagnosticSpec(locationMarker: "END", message: "Expected expression after '->'")
527+
DiagnosticSpec(locationMarker: "END", message: "Expected expression")
528528
]
529529
)
530530
}

Tests/SwiftParserTest/Statements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class StatementTests: XCTestCase {
4545
}
4646
""",
4747
diagnostics: [
48-
DiagnosticSpec(message: "Expected expression after 'case' in pattern"),
48+
DiagnosticSpec(message: "Expected expression in pattern"),
4949
DiagnosticSpec(message: "Expected '=' and expression in pattern matching"),
5050
DiagnosticSpec(message: "Unexpected text '* ! = x' in 'if' statement"),
5151
]

Tests/SwiftParserTest/Types.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ final class TypeTests: XCTestCase {
3131

3232
func testFunctionTypes() throws {
3333
AssertParse("t as(#^DIAG^#..)->#^END^#", diagnostics: [
34-
DiagnosticSpec(message: "Expected type after '(' in function type"),
34+
DiagnosticSpec(message: "Expected type in function type"),
3535
DiagnosticSpec(message: "Unexpected text '..' in function type"),
36-
DiagnosticSpec(locationMarker: "END", message: "Expected type after '->' in function type"),
36+
DiagnosticSpec(locationMarker: "END", message: "Expected type in function type"),
3737
])
3838
}
3939

@@ -95,8 +95,8 @@ final class TypeTests: XCTestCase {
9595
"""#,
9696
diagnostics: [
9797
// FIXME: This should be a valid parse
98-
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected expression after 'i' in key path"),
99-
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected expression after 'i' in key path"),
98+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected expression in key path"),
99+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected expression in key path"),
100100
]
101101
)
102102
}

0 commit comments

Comments
 (0)