Skip to content

Commit 77ad256

Browse files
authored
Merge pull request #80130 from swiftlang/egorzhdan/submodules-name-for-lookup
[cxx-interop] Determine owning module correctly for C++ decls in nested modules
2 parents 8fd02d7 + 106a6af commit 77ad256

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

lib/AST/Decl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,10 @@ static ModuleDecl *getModuleContextForNameLookupForCxxDecl(const Decl *decl) {
916916
if (!clangModule)
917917
return nullptr;
918918

919+
// Swift groups all submodules of a Clang module together, and imports them as
920+
// a single top-level module.
921+
clangModule = clangModule->getTopLevelModule();
922+
919923
return ctx.getClangModuleLoader()->getWrapperForModule(clangModule);
920924
}
921925

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
namespace NS {
2+
} // namespace NS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace NS {
2+
3+
struct MyStructInDeepSubModule {};
4+
5+
} // namespace NS

test/Interop/Cxx/modules/Inputs/module.modulemap

+15
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,18 @@ module Namespaces {
22
header "namespace.h"
33
requires cplusplus
44
}
5+
6+
module TopLevelModule {
7+
module SubModule {
8+
module DeepSubModule {
9+
header "deep-submodule.h"
10+
export *
11+
}
12+
module AnotherDeepSubModule {
13+
header "another-deep-submodule.h"
14+
export *
15+
}
16+
export *
17+
}
18+
export *
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=default
2+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=default -enable-upcoming-feature MemberImportVisibility
3+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=default -D IMPORT_TOP_LEVEL
4+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=default -D IMPORT_ANOTHER_SUBMODULE
5+
6+
// REQUIRES: swift_feature_MemberImportVisibility
7+
8+
#if IMPORT_TOP_LEVEL
9+
import TopLevelModule
10+
#elseif IMPORT_ANOTHER_SUBMODULE
11+
import TopLevelModule.SubModule.AnotherDeepSubModule
12+
#else
13+
import TopLevelModule.SubModule.DeepSubModule
14+
#endif
15+
16+
let _: NS.MyStructInDeepSubModule! = nil
17+
18+
extension NS.MyStructInDeepSubModule {
19+
public static func takesInstance(_ i: NS.MyStructInDeepSubModule) {}
20+
}

0 commit comments

Comments
 (0)