@@ -4613,7 +4613,7 @@ namespace {
4613
4613
4614
4614
// Create the extension declaration and record it.
4615
4615
objcClass->addExtension (result);
4616
- Impl.ImportedDecls [{decl-> getCanonicalDecl () , getVersion ()}] = result;
4616
+ Impl.ImportedDecls [{decl, getVersion ()}] = result;
4617
4617
SmallVector<TypeLoc, 4 > inheritedTypes;
4618
4618
importObjCProtocols (result, decl->getReferencedProtocols (),
4619
4619
inheritedTypes);
@@ -7380,8 +7380,10 @@ void SwiftDeclConverter::importInheritedConstructors(
7380
7380
7381
7381
Decl *ClangImporter::Implementation::importDeclCached (
7382
7382
const clang::NamedDecl *ClangDecl,
7383
- ImportNameVersion version) {
7384
- auto Known = ImportedDecls.find ({ClangDecl->getCanonicalDecl (), version});
7383
+ ImportNameVersion version,
7384
+ bool UseCanonical) {
7385
+ auto Known = ImportedDecls.find (
7386
+ { UseCanonical? ClangDecl->getCanonicalDecl (): ClangDecl, version });
7385
7387
if (Known != ImportedDecls.end ())
7386
7388
return Known->second ;
7387
7389
@@ -7970,7 +7972,8 @@ void ClangImporter::Implementation::finishNormalConformance(
7970
7972
Decl *ClangImporter::Implementation::importDeclAndCacheImpl (
7971
7973
const clang::NamedDecl *ClangDecl,
7972
7974
ImportNameVersion version,
7973
- bool SuperfluousTypedefsAreTransparent) {
7975
+ bool SuperfluousTypedefsAreTransparent,
7976
+ bool UseCanonicalDecl) {
7974
7977
if (!ClangDecl)
7975
7978
return nullptr ;
7976
7979
@@ -7979,9 +7982,9 @@ Decl *ClangImporter::Implementation::importDeclAndCacheImpl(
7979
7982
clang::PrettyStackTraceDecl trace (ClangDecl, clang::SourceLocation (),
7980
7983
Instance->getSourceManager (), " importing" );
7981
7984
7982
- auto Canon = cast<clang::NamedDecl>(ClangDecl->getCanonicalDecl ());
7985
+ auto Canon = cast<clang::NamedDecl>(UseCanonicalDecl? ClangDecl->getCanonicalDecl (): ClangDecl );
7983
7986
7984
- if (auto Known = importDeclCached (Canon, version)) {
7987
+ if (auto Known = importDeclCached (Canon, version, UseCanonicalDecl )) {
7985
7988
if (!SuperfluousTypedefsAreTransparent &&
7986
7989
SuperfluousTypedefs.count (Canon))
7987
7990
return nullptr ;
@@ -8082,8 +8085,11 @@ DeclContext *ClangImporter::Implementation::importDeclContextImpl(
8082
8085
auto decl = dyn_cast<clang::NamedDecl>(dc);
8083
8086
if (!decl)
8084
8087
return nullptr ;
8085
-
8086
- auto swiftDecl = importDecl (decl, CurrentVersion);
8088
+ // Category decls with same name can be merged and using canonical decl always
8089
+ // leads to the first category of the given name. We'd like to keep these
8090
+ // categories separated.
8091
+ auto useCanonical = !isa<clang::ObjCCategoryDecl>(decl);
8092
+ auto swiftDecl = importDecl (decl, CurrentVersion, useCanonical);
8087
8093
if (!swiftDecl)
8088
8094
return nullptr ;
8089
8095
0 commit comments