Files
swift-mirror/test/SymbolGraph/ClangImporter/HeaderNameCollision.swift
QuietMisdreavus 0cc46765ec [SymbolGraphGen] distinguish between headers of the same name in different modules (#82112)
Resolves rdar://152676102

In Objective-C, it's reasonable to sort extensions of your dependency's
types into headers that match the name of that type. However, this runs
into a bug in SymbolGraphGen when it comes time to generate Swift symbol
graphs for that Objective-C code: At the moment, it only differentiates
between modules based on their base name, regardless of their parent
modules (if any). This causes these extensions to be incorrectly sorted
into the _extending module's_ symbol graph, rather than in an extension
symbol graph where it can be displayed with the _extended module_. When
processed with Swift-DocC, it would cause these symbols to disappear.

This PR updates the `areModulesEqual` function used by the
`SymbolGraphASTWalker` to consider the fully-qualified module name for
comparisons, rather than just the module's base name, causing situations
like the test's `Dependency.DependencyClass` and
`HeaderCollision.DependencyClass` to be properly distinguished from each
other.
2025-06-09 15:11:31 -06:00

54 lines
1.6 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-symbolgraph-extract -sdk %clang-importer-sdk -module-name HeaderCollision -F %t -output-dir %t -pretty-print -v
// RUN: %FileCheck %s --input-file %t/HeaderCollision.symbols.json --check-prefix MODULE
// RUN: %FileCheck %s --input-file %t/HeaderCollision@Dependency.symbols.json --check-prefix EXTENSION
// REQUIRES: objc_interop
// Ensure that extensions to a dependency's types, declared in a header with the same name as the
// dependency's type's header, correctly get sorted into an extension header rather than the module
// itself.
// MODULE: "symbols": []
// EXTENSION: "precise": "c:objc(cs)DependencyClass(im)addNumber:to:"
//--- Dependency.framework/Modules/module.modulemap
framework module Dependency {
umbrella header "Dependency.h"
export *
module * { export * }
}
//--- Dependency.framework/Headers/Dependency.h
#import <Dependency/DependencyClass.h>
//--- Dependency.framework/Headers/DependencyClass.h
@import Foundation;
@class DependencyClass;
@interface DependencyClass : NSObject
@end
//--- HeaderCollision.framework/Modules/module.modulemap
framework module HeaderCollision {
umbrella header "HeaderCollision.h"
export *
module * { export * }
}
//--- HeaderCollision.framework/Headers/HeaderCollision.h
#import <HeaderCollision/DependencyClass.h>
//--- HeaderCollision.framework/Headers/DependencyClass.h
#import <Dependency/DependencyClass.h>
@interface DependencyClass (HeaderCollisionClassAdditions)
- (NSInteger)addNumber:(NSInteger)x to:(NSInteger)y;
@end