Skip to content

Commit ad94d55

Browse files
authored
Merge pull request #76410 from xymus/public-module-name-fix-loaded
Sema: Fix `getPublicModuleName` to look only at loaded modules
2 parents 52d9d80 + f9a8a67 commit ad94d55

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

lib/AST/Module.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,15 +1923,11 @@ ImportedModule::removeDuplicates(SmallVectorImpl<ImportedModule> &imports) {
19231923
}
19241924

19251925
Identifier ModuleDecl::getPublicModuleName(bool onlyIfImported) const {
1926-
if (!PublicModuleName.empty()) {
1927-
if (!onlyIfImported)
1928-
return PublicModuleName;
1926+
if (!PublicModuleName.empty() &&
1927+
(!onlyIfImported ||
1928+
getASTContext().getLoadedModule(PublicModuleName)))
1929+
return PublicModuleName;
19291930

1930-
bool publicModuleIsImported =
1931-
getASTContext().getModuleByIdentifier(PublicModuleName);
1932-
if (publicModuleIsImported)
1933-
return PublicModuleName;
1934-
}
19351931
return getName();
19361932
}
19371933

test/Sema/public-module-name.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
// RUN: -verify
4848
// RUN: not %target-swift-frontend -typecheck %t/ClientMiddle.swift -o %t -I %t \
4949
// RUN: -enable-library-evolution -swift-version 6 \
50+
// RUN: -diagnostic-style llvm \
5051
// RUN: 2>&1 | %FileCheck %t/ClientMiddle.swift
5152

5253
/// Test more diagnostics referencing modules.
@@ -69,6 +70,7 @@
6970
// RUN: -verify
7071
// RUN: not %target-swift-frontend -typecheck %t/ClientMiddle.swift -o %t -I %t \
7172
// RUN: -enable-library-evolution -swift-version 6 \
73+
// RUN: -diagnostic-style llvm \
7274
// RUN: 2>&1 | %FileCheck %t/ClientMiddle.swift
7375

7476
// RUN: %target-swift-frontend -typecheck %t/ClientAccessLevelOnImports.swift -o %t -I %t \

0 commit comments

Comments
 (0)