Skip to content

Commit 976c858

Browse files
committed
Address PR feedback: child symbol is non-optional
1 parent 67e522d commit 976c858

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Sources/SwiftDocC/Infrastructure/Symbol Graph/GeneratedDocumentationTopics.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum GeneratedDocumentationTopics {
4040
/// - reference: The parent type reference.
4141
/// - originDisplayName: The origin display name as provided by the symbol graph.
4242
/// - extendedModuleName: Extended module name.
43-
mutating func add(_ childReference: ResolvedTopicReference, to reference: ResolvedTopicReference, originDisplayName: String, originSymbol: SymbolGraph.Symbol?, sourceSymbol: SymbolGraph.Symbol?, extendedModuleName: String) throws {
43+
mutating func add(_ childReference: ResolvedTopicReference, to reference: ResolvedTopicReference, childSymbol: SymbolGraph.Symbol, originDisplayName: String, originSymbol: SymbolGraph.Symbol?, extendedModuleName: String) throws {
4444
let fromType: String
4545
let typeSimpleName: String
4646
if let originSymbol = originSymbol, originSymbol.pathComponents.count > 1 {
@@ -49,9 +49,8 @@ enum GeneratedDocumentationTopics {
4949
let parentSymbolPathComponents = originSymbol.pathComponents.dropLast()
5050
fromType = parentSymbolPathComponents.joined(separator: ".")
5151
typeSimpleName = parentSymbolPathComponents.last!
52-
} else if let sourceSymbol = sourceSymbol,
53-
let sourceSymbolName = sourceSymbol.pathComponents.last,
54-
originDisplayName.count > (sourceSymbolName.count + 1)
52+
} else if let childSymbolName = childSymbol.pathComponents.last,
53+
originDisplayName.count > (childSymbolName.count + 1)
5554
{
5655
// In the case where we don't have a resolved symbol for the source origin,
5756
// this allows us to still accurately handle cases like this:
@@ -63,13 +62,13 @@ enum GeneratedDocumentationTopics {
6362
// of the symbol name (+1 for the period splitting the names)
6463
// from the source is a reliable way to support this.
6564

66-
let parentSymbolName = originDisplayName.dropLast(sourceSymbolName.count + 1)
65+
let parentSymbolName = originDisplayName.dropLast(childSymbolName.count + 1)
6766
fromType = String(parentSymbolName)
6867
typeSimpleName = String(parentSymbolName.split(separator: ".").last ?? parentSymbolName)
6968
} else {
70-
// If we don't have a resolved source origin symbol or source symbol, fall back to
71-
// parsing its display name. This should never happen since we expect to
72-
// always have a source symbol.
69+
// This should never happen but is a last safeguard for the case where
70+
// the child symbol is unexpectedly short. In this case, we can attempt to just parse
71+
// the parent symbol name out of the origin display name.
7372

7473
// Detect the path components of the providing the default implementation.
7574
let typeComponents = originDisplayName.split(separator: ".")
@@ -244,13 +243,14 @@ enum GeneratedDocumentationTopics {
244243
let parent = context.symbolIndex[relationship.target],
245244
// Resolve the child
246245
let child = context.symbolIndex[relationship.source],
246+
// Get the child symbol
247+
let childSymbol = child.symbol,
247248
// Get the swift extension data
248-
let extends = child.symbol?.mixins[SymbolGraph.Symbol.Swift.Extension.mixinKey] as? SymbolGraph.Symbol.Swift.Extension {
249+
let extends = childSymbol.mixins[SymbolGraph.Symbol.Swift.Extension.mixinKey] as? SymbolGraph.Symbol.Swift.Extension {
249250
let originSymbol = context.symbolIndex[origin.identifier]?.symbol
250-
let sourceSymbol = context.symbolIndex[relationship.source]?.symbol
251251

252252
// Add the inherited symbol to the index.
253-
try inheritanceIndex.add(child.reference, to: parent.reference, originDisplayName: origin.displayName, originSymbol: originSymbol, sourceSymbol: sourceSymbol, extendedModuleName: extends.extendedModule)
253+
try inheritanceIndex.add(child.reference, to: parent.reference, childSymbol: childSymbol, originDisplayName: origin.displayName, originSymbol: originSymbol, extendedModuleName: extends.extendedModule)
254254
}
255255
}
256256

0 commit comments

Comments
 (0)