Skip to content

Commit 53e0fad

Browse files
authored
Assume it's okay for decls in a cross-module extension to be public (swiftlang#18741)
...even if the base decl isn't. This isn't normally possible, but it can come up when an imported type is import-as-member'd onto an internal Swift declaration. This isn't even such an unreasonable thing to do, since internal Swift declarations are exposed in the generated header for an app. rdar://problem/43312660
1 parent 34f6a1f commit 53e0fad

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,10 +2482,12 @@ getAccessScopeForFormalAccess(const ValueDecl *VD,
24822482
// Just check the base type. If it's a constrained extension, Sema should
24832483
// have already enforced access more strictly.
24842484
if (auto nominal = enclosingExt->getExtendedNominal()) {
2485-
auto nominalAccess =
2486-
getAdjustedFormalAccess(nominal, useDC,
2487-
treatUsableFromInlineAsPublic);
2488-
access = std::min(access, nominalAccess);
2485+
if (nominal->getParentModule() == enclosingExt->getParentModule()) {
2486+
auto nominalAccess =
2487+
getAdjustedFormalAccess(nominal, useDC,
2488+
treatUsableFromInlineAsPublic);
2489+
access = std::min(access, nominalAccess);
2490+
}
24892491
}
24902492

24912493
} else {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@class Outer;
2+
3+
struct Nested {
4+
int value;
5+
} __attribute((swift_name("Outer.Nested")));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-frontend -import-objc-header %S/Inputs/import-as-member-swift.h -typecheck -enable-objc-interop -disable-objc-attr-requires-foundation-module %s
2+
3+
@objc internal class Outer {}
4+
5+
_ = Outer.Nested()

0 commit comments

Comments
 (0)