Skip to content

Commit b76e07f

Browse files
authored
Don't omit "Type" suffix from disambiguation for Swift metatypes (#1230)
* Don't omit "Type" suffix from disambiguation for Swift metatype parameters rdar://152496046 * Remove trailing commas for compatibility before Swift 6.1
1 parent b9c4b50 commit b76e07f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+TypeSignature.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ extension PathHierarchy {
136136
// For example: "[", "?", "<", "...", ",", "(", "->" etc. contribute to the type spellings like
137137
// `[Name]`, `Name?`, "Name<T>", "Name...", "()", "(Name, Name)", "(Name)->Name" and more.
138138
let utf8Spelling = fragment.spelling.utf8
139+
guard !utf8Spelling.elementsEqual(".Type".utf8) else {
140+
// Once exception to that is "Name.Type" which is different from just "Name" (and we don't want a trailing ".")
141+
accumulated.append(contentsOf: utf8Spelling)
142+
continue
143+
}
139144
for index in utf8Spelling.indices {
140145
let char = utf8Spelling[index]
141146
switch char {

Tests/SwiftDocCTests/Infrastructure/PathHierarchyTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,6 +3772,42 @@ class PathHierarchyTests: XCTestCase {
37723772
])
37733773
}
37743774

3775+
// The second overload refers to the metatype of the parameter
3776+
do {
3777+
func makeSignature(first: DeclToken...) -> SymbolGraph.Symbol.FunctionSignature {
3778+
.init(
3779+
parameters: [.init(name: "first", externalName: "with", declarationFragments: makeFragments(first), children: []),],
3780+
returns: makeFragments([voidType])
3781+
)
3782+
}
3783+
3784+
let someGenericTypeID = "some-generic-type-id"
3785+
let catalog = Folder(name: "unit-test.docc", content: [
3786+
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(
3787+
moduleName: "ModuleName",
3788+
symbols: [
3789+
makeSymbol(id: "function-overload-1", kind: .func, pathComponents: ["doSomething(with:)"], signature: makeSignature(
3790+
// GenericName
3791+
first: .typeIdentifier("GenericName", precise: someGenericTypeID)
3792+
)),
3793+
3794+
makeSymbol(id: "function-overload-2", kind: .func, pathComponents: ["doSomething(with:)"], signature: makeSignature(
3795+
// GenericName.Type
3796+
first: .typeIdentifier("GenericName", precise: someGenericTypeID), ".Type"
3797+
)),
3798+
]
3799+
))
3800+
])
3801+
3802+
let (_, context) = try loadBundle(catalog: catalog)
3803+
let tree = context.linkResolver.localResolver.pathHierarchy
3804+
3805+
try assertPathCollision("ModuleName/doSomething(with:)", in: tree, collisions: [
3806+
(symbolID: "function-overload-1", disambiguation: "-(GenericName)"), // GenericName
3807+
(symbolID: "function-overload-2", disambiguation: "-(GenericName.Type)"), // GenericName.Type
3808+
])
3809+
}
3810+
37753811
// Second overload requires combination of two non-unique types to disambiguate
37763812
do {
37773813
// String Set<Int> (Double)->Void

0 commit comments

Comments
 (0)