Skip to content

Commit 1c2ba45

Browse files
committed
[interop] namespace printing should only print redecls from one module interface
This ensures that when we're printing multiple module interfaces, we separate out the namespaces and their members correctly between the produced module interfaces.
1 parent 8c6d50c commit 1c2ba45

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,15 @@ static void addNamespaceMembers(Decl *decl,
23002300

23012301
// This is only to keep track of the members we've already seen.
23022302
llvm::SmallPtrSet<Decl *, 16> addedMembers;
2303+
const auto *declOwner = namespaceDecl->getOwningModule();
2304+
if (declOwner)
2305+
declOwner = declOwner->getTopLevelModule();
23032306
for (auto redecl : namespaceDecl->redecls()) {
2307+
// Skip namespace declarations that come from other top-level modules.
2308+
if (const auto *redeclOwner = redecl->getOwningModule()) {
2309+
if (declOwner && declOwner != redeclOwner->getTopLevelModule())
2310+
continue;
2311+
}
23042312
for (auto member : redecl->decls()) {
23052313
if (auto classTemplate = dyn_cast<clang::ClassTemplateDecl>(member)) {
23062314
// Add all specializations to a worklist so we don't accidently mutate
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-ide-test -print-module -module-to-print=ModuleB -I %t/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck --check-prefix=CHECKB %s
4+
// RUN: %target-swift-ide-test -print-module -module-to-print=ModuleA -I %t/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck --check-prefix=CHECKA %s
5+
6+
//--- Inputs/module.modulemap
7+
module ModuleA {
8+
header "headerA.h"
9+
requires cplusplus
10+
}
11+
12+
module ModuleB {
13+
header "headerB.h"
14+
requires cplusplus
15+
}
16+
17+
//--- Inputs/headerA.h
18+
19+
namespace ns {
20+
struct A {
21+
int x;
22+
};
23+
}
24+
25+
//--- Inputs/headerB.h
26+
27+
#include "headerA.h"
28+
29+
namespace ns {
30+
struct B {
31+
int y;
32+
};
33+
}
34+
35+
// CHECKB: enum ns {
36+
// CHECKB-NEXT: struct B {
37+
// CHECKB-NEXT: init()
38+
// CHECKB-NEXT: init(y: Int32)
39+
// CHECKB-NEXT: var y: Int32
40+
// CHECKB-NEXT: }
41+
// CHECKB-NEXT: }
42+
43+
// CHECKA: enum ns {
44+
// CHECKA-NEXT: struct A {
45+
// CHECKA-NEXT: init()
46+
// CHECKA-NEXT: init(x: Int32)
47+
// CHECKA-NEXT: var x: Int32
48+
// CHECKA-NEXT: }
49+
// CHECKA-NEXT: }

0 commit comments

Comments
 (0)