Skip to content

Commit 2fe34ac

Browse files
committed
Run ParseDiagnosticGenerator for mutated test cases
Just make sure that we don’t crash the diagnostic generator with the mutated test cases.
1 parent 15cc691 commit 2fe34ac

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

Sources/SwiftParser/Nominals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ extension Parser {
333333
}
334334

335335
mutating func parsePrimaryAssociatedTypes() -> RawPrimaryAssociatedTypeClauseSyntax {
336-
let langle = self.consumeAnyToken(remapping: .leftAngle)
336+
let langle = self.consumePrefix("<", as: .leftAngle)
337337
var associatedTypes = [RawPrimaryAssociatedTypeSyntax]()
338338
do {
339339
var keepGoing: RawTokenSyntax? = nil

Tests/SwiftParserTest/Assertions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ fileprivate func assertRoundTrip<S: SyntaxProtocol>(
560560
// the mutated source and that it round-trips
561561
var mutatedParser = Parser(buf)
562562
let mutatedTree = parse(&mutatedParser)
563+
// Run the diagnostic generator to make sure it doesn’t crash
564+
_ = ParseDiagnosticsGenerator.diagnostics(for: mutatedTree)
563565
assertStringsEqualWithDiff(
564566
"\(mutatedTree)",
565567
mutatedSource,

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,4 +2222,14 @@ final class DeclarationTests: XCTestCase {
22222222
"""
22232223
)
22242224
}
2225+
2226+
func testEmptyPrimaryAssociatedType() {
2227+
assertParse(
2228+
"protocol X<1️⃣> {}",
2229+
diagnostics: [
2230+
DiagnosticSpec(message: "expected name in primary associated type clause", fixIts: ["insert name"])
2231+
],
2232+
fixedSource: "protocol X<<#identifier#>> {}"
2233+
)
2234+
}
22252235
}

Tests/SwiftParserTest/StatementTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ final class StatementTests: XCTestCase {
9696
}
9797

9898
func testNestedIfs() {
99-
let nest = 20
99+
let nest = 10
100100
var source = "func nestThoseIfs() {\n"
101101
for index in (0...nest) {
102102
let indent = String(repeating: " ", count: index + 1)

0 commit comments

Comments
 (0)