Skip to content

[6.2] Don't omit "Type" suffix from disambiguation for Swift metatypes #1240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ extension PathHierarchy {
// For example: "[", "?", "<", "...", ",", "(", "->" etc. contribute to the type spellings like
// `[Name]`, `Name?`, "Name<T>", "Name...", "()", "(Name, Name)", "(Name)->Name" and more.
let utf8Spelling = fragment.spelling.utf8
guard !utf8Spelling.elementsEqual(".Type".utf8) else {
// Once exception to that is "Name.Type" which is different from just "Name" (and we don't want a trailing ".")
accumulated.append(contentsOf: utf8Spelling)
continue
}
for index in utf8Spelling.indices {
let char = utf8Spelling[index]
switch char {
Expand Down
36 changes: 36 additions & 0 deletions Tests/SwiftDocCTests/Infrastructure/PathHierarchyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3772,6 +3772,42 @@ class PathHierarchyTests: XCTestCase {
])
}

// The second overload refers to the metatype of the parameter
do {
func makeSignature(first: DeclToken...) -> SymbolGraph.Symbol.FunctionSignature {
.init(
parameters: [.init(name: "first", externalName: "with", declarationFragments: makeFragments(first), children: []),],
returns: makeFragments([voidType])
)
}

let someGenericTypeID = "some-generic-type-id"
let catalog = Folder(name: "unit-test.docc", content: [
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(
moduleName: "ModuleName",
symbols: [
makeSymbol(id: "function-overload-1", kind: .func, pathComponents: ["doSomething(with:)"], signature: makeSignature(
// GenericName
first: .typeIdentifier("GenericName", precise: someGenericTypeID)
)),

makeSymbol(id: "function-overload-2", kind: .func, pathComponents: ["doSomething(with:)"], signature: makeSignature(
// GenericName.Type
first: .typeIdentifier("GenericName", precise: someGenericTypeID), ".Type"
)),
]
))
])

let (_, context) = try loadBundle(catalog: catalog)
let tree = context.linkResolver.localResolver.pathHierarchy

try assertPathCollision("ModuleName/doSomething(with:)", in: tree, collisions: [
(symbolID: "function-overload-1", disambiguation: "-(GenericName)"), // GenericName
(symbolID: "function-overload-2", disambiguation: "-(GenericName.Type)"), // GenericName.Type
])
}

// Second overload requires combination of two non-unique types to disambiguate
do {
// String Set<Int> (Double)->Void
Expand Down