Skip to content

Commit 05954ea

Browse files
committed
[AST] Account for non-user modules in isPrivateStdlibDecl
Consider both non-user and system modules when checking whether an underscored decl should be considered private. rdar://131854240
1 parent 9bd0426 commit 05954ea

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

lib/AST/Decl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,17 +1141,16 @@ bool Decl::isPrivateStdlibDecl(bool treatNonBuiltinProtocolsAsPublic) const {
11411141
}
11421142

11431143
DeclContext *DC = D->getDeclContext()->getModuleScopeContext();
1144-
if (DC->getParentModule()->isBuiltinModule() ||
1145-
DC->getParentModule()->isSwiftShimsModule())
1144+
auto *M = DC->getParentModule();
1145+
if (M->isBuiltinModule() || M->isSwiftShimsModule())
11461146
return true;
1147-
if (!DC->getParentModule()->isSystemModule())
1147+
if (!M->isSystemModule() && !M->isNonUserModule())
11481148
return false;
11491149
auto FU = dyn_cast<FileUnit>(DC);
11501150
if (!FU)
11511151
return false;
1152-
// Check for Swift module and overlays.
1153-
if (!DC->getParentModule()->isStdlibModule() &&
1154-
FU->getKind() != FileUnitKind::SerializedAST)
1152+
// Check for stdlib and imported Swift modules.
1153+
if (!M->isStdlibModule() && FU->getKind() != FileUnitKind::SerializedAST)
11551154
return false;
11561155

11571156
if (isa<ProtocolDecl>(D)) {

test/IDE/complete_rdar131854240.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %empty-directory(%t/completions)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %empty-directory(%t/Mock.platform/Developer/SDKs)
5+
// RUN: cp -r %clang-importer-sdk-path %t/Mock.platform/Developer/SDKs/Mock.sdk
6+
7+
// RUN: %empty-directory(%t/Mock.platform/Developer/usr/lib/Lib.swiftmodule)
8+
// RUN: %target-swift-frontend -emit-module %t/lib.swift -module-name Lib -swift-version 5 -emit-module-path %t/Mock.platform/Developer/usr/lib/Lib.swiftmodule/%module-target-triple.swiftmodule -enable-library-evolution -emit-module-interface-path %t/Mock.platform/Developer/usr/lib/Lib.swiftmodule/%module-target-triple.swiftinterface
9+
10+
// RUN: %target-swift-ide-test(mock-sdk: -sdk %t/Mock.platform/Developer/SDKs/Mock.sdk -I %t/Mock.platform/Developer/usr/lib) -batch-code-completion -source-filename %t/client.swift -filecheck %raw-FileCheck -completion-output-dir %t/completions
11+
12+
// REQUIRES: objc_interop
13+
14+
// rdar://131854240 - Make sure we don't show underscored decls in non-user
15+
// modules.
16+
17+
//--- lib.swift
18+
19+
public struct SomeNonUnderscoredType {}
20+
public struct _SomeUnderscoredType {}
21+
22+
//--- client.swift
23+
24+
import Lib
25+
26+
#^TOPLEVEL?check=TOPLEVEL;check=TOPLEVEL_NOT^#
27+
// TOPLEVEL: Decl[Struct]/OtherModule[Lib]/IsSystem: SomeNonUnderscoredType[#SomeNonUnderscoredType#]
28+
// TOPLEVEL_NOT-NOT: _SomeUnderscoredType

0 commit comments

Comments
 (0)