Skip to content

Commit a54c164

Browse files
Don't decode empty bystander arrays.
If a bystandar array is empty after decoding it don't initialize the value. Usally this wouldn't happen, but if it does, it can break DocC. rdar://162596256
1 parent 3fc0c68 commit a54c164

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Sources/SymbolKit/SymbolGraph/Module.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2025 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -40,7 +40,9 @@ extension SymbolGraph {
4040
public init(from decoder: Decoder) throws {
4141
let container = try decoder.container(keyedBy: CodingKeys.self)
4242
self.name = try container.decode(String.self, forKey: .name)
43-
self.bystanders = try container.decodeIfPresent([String].self, forKey: .bystanders)
43+
if let bystanders = try container.decodeIfPresent([String].self, forKey: .bystanders) {
44+
self.bystanders = bystanders.isEmpty ? nil : bystanders
45+
}
4446
self.platform = try container.decode(Platform.self, forKey: .platform)
4547
self.version = try container.decodeIfPresent(SemanticVersion.self, forKey: .version)
4648
self.isVirtual = try container.decodeIfPresent(Bool.self, forKey: .isVirtual) ?? false

Tests/SymbolKitTests/SymbolGraph/ModuleTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ class ModuleTests: XCTestCase {
4444
let decodedModule = try module.roundTripDecode()
4545
XCTAssertEqual(["A"], decodedModule.bystanders)
4646
}
47+
48+
do {
49+
// bystanders = []
50+
let module = SymbolGraph.Module(name: "Test", platform: ModuleTests.platform, bystanders: [])
51+
let decodedModule = try module.roundTripDecode()
52+
XCTAssertNil(decodedModule.bystanders)
53+
}
4754
}
4855

4956
func testOptionalIsVirtual() throws {

0 commit comments

Comments
 (0)