From a54c1644586945bf2a1487bdc732b0a5f01c8621 Mon Sep 17 00:00:00 2001 From: Sofia Rodriguez Morales Date: Mon, 13 Oct 2025 18:44:53 +0100 Subject: [PATCH] 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 --- Sources/SymbolKit/SymbolGraph/Module.swift | 6 ++++-- Tests/SymbolKitTests/SymbolGraph/ModuleTests.swift | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/SymbolKit/SymbolGraph/Module.swift b/Sources/SymbolKit/SymbolGraph/Module.swift index a5115a8..7b077da 100644 --- a/Sources/SymbolKit/SymbolGraph/Module.swift +++ b/Sources/SymbolKit/SymbolGraph/Module.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021 Apple Inc. and the Swift project authors + Copyright (c) 2021-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information @@ -40,7 +40,9 @@ extension SymbolGraph { public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.name = try container.decode(String.self, forKey: .name) - self.bystanders = try container.decodeIfPresent([String].self, forKey: .bystanders) + if let bystanders = try container.decodeIfPresent([String].self, forKey: .bystanders) { + self.bystanders = bystanders.isEmpty ? nil : bystanders + } self.platform = try container.decode(Platform.self, forKey: .platform) self.version = try container.decodeIfPresent(SemanticVersion.self, forKey: .version) self.isVirtual = try container.decodeIfPresent(Bool.self, forKey: .isVirtual) ?? false diff --git a/Tests/SymbolKitTests/SymbolGraph/ModuleTests.swift b/Tests/SymbolKitTests/SymbolGraph/ModuleTests.swift index ab407e3..4ff7f50 100644 --- a/Tests/SymbolKitTests/SymbolGraph/ModuleTests.swift +++ b/Tests/SymbolKitTests/SymbolGraph/ModuleTests.swift @@ -44,6 +44,13 @@ class ModuleTests: XCTestCase { let decodedModule = try module.roundTripDecode() XCTAssertEqual(["A"], decodedModule.bystanders) } + + do { + // bystanders = [] + let module = SymbolGraph.Module(name: "Test", platform: ModuleTests.platform, bystanders: []) + let decodedModule = try module.roundTripDecode() + XCTAssertNil(decodedModule.bystanders) + } } func testOptionalIsVirtual() throws {