Skip to content

Commit 1ed3a9b

Browse files
authored
[Serialized diagnostics] Ignore unknown records. (#379)
To improve forward compatibility, ignore any unknown records encountered during deserialization rather than throwing an error. libclang has behaved this way forever, and we should do the same.
1 parent 284a418 commit 1ed3a9b

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Sources/TSCUtility/SerializedDiagnostics.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ extension SerializedDiagnostics {
129129
}
130130

131131
case .version, nil:
132-
throw Error.unexpectedRecord
132+
// Ignore unknown records, for future compatibility
133+
continue
133134
}
134135
}
135136

12.7 KB
Binary file not shown.

Tests/TSCUtilityTests/SerializedDiagnosticsTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ final class SerializedDiagnosticsTests: XCTestCase {
163163
XCTAssertEqual(diag.fixIts.count, 0)
164164
}
165165

166+
func testReadDiagsWithUnknownRecord() throws {
167+
let serializedDiagnosticsPath = AbsolutePath(path: #file).parentDirectory
168+
.appending(components: "Inputs", "string_init_ambig.dia")
169+
let contents = try localFileSystem.readFileContents(serializedDiagnosticsPath)
170+
let serializedDiags = try SerializedDiagnostics(bytes: contents)
171+
172+
XCTAssertEqual(serializedDiags.versionNumber, 2)
173+
XCTAssertEqual(serializedDiags.diagnostics.count, 35)
174+
}
175+
166176
func testReadClangSerializedDiags() throws {
167177
let serializedDiagnosticsPath = AbsolutePath(path: #file).parentDirectory
168178
.appending(components: "Inputs", "clang.dia")

0 commit comments

Comments
 (0)