Skip to content

Commit 903937a

Browse files
committed
Exempt C++ namespaces from internal-import checking
C++ namespaces always get imported into the bridging header's module for Reasons. Exempt them from internal-import checking, since we get checking for the namespace members that are actually used.
1 parent b13c2ae commit 903937a

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,11 @@ void swift::recordRequiredImportAccessLevelForDecl(
26942694
if (definingModule == dc->getParentModule())
26952695
return;
26962696

2697+
// Egregious hack: if the declaration is for a C++ namespace, assume it's
2698+
// accessible.
2699+
if (isa_and_nonnull<clang::NamespaceDecl>(decl->getClangDecl()))
2700+
return;
2701+
26972702
sf->registerRequiredAccessLevelForModule(definingModule, accessLevel);
26982703

26992704
if (auto attributedImport = sf->getImportAccessLevel(definingModule)) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
namespace OuterNS {
3+
class MyPoint {
4+
public:
5+
double x, y;
6+
};
7+
}
8+
9+
#include "cxx-outer-ns.h"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace OuterNS {
2+
enum Color {
3+
red,
4+
green,
5+
blue
6+
};
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module CXXOuterNS {
2+
header "cxx-outer-ns.h"
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-typecheck-verify-swift -internal-import-bridging-header %S/../Inputs/cxx-bridging-header.h -sdk %clang-importer-sdk -cxx-interoperability-mode=default -I %S/../Inputs
2+
3+
public func getRed() -> OuterNS.Color { OuterNS.red }
4+
// expected-error@-1{{function cannot be declared public because its result uses an internal type}}
5+
// expected-note@-2{{enum 'OuterNS' is imported by this file as 'internal' from bridging header}}
6+
7+
public func getX(point: OuterNS.MyPoint) -> Double { point.x }
8+
// expected-error@-1{{function cannot be declared public because its parameter uses an internal type}}
9+
// expected-note@-2{{enum 'OuterNS' is imported by this file as 'internal' from bridging header}}

0 commit comments

Comments
 (0)