Skip to content

Commit a1270f6

Browse files
committed
[Serialization] Support loading an aliased module with an underlying module
Importing a module using an alias (set with -module-alias) fails if the imported module has an underlying clang module. rdar://102217790
1 parent 66586b5 commit a1270f6

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ class ModuleInterfaceLoaderImpl {
614614
StringRef inParentDirName =
615615
path::filename(path::parent_path(interfacePath));
616616
if (path::extension(inParentDirName) == ".swiftmodule") {
617-
assert(path::stem(inParentDirName) == moduleName);
617+
assert(path::stem(inParentDirName) ==
618+
ctx.getRealModuleName(ctx.getIdentifier(moduleName)).str());
618619
path::append(scratch, inParentDirName);
619620
}
620621
path::append(scratch, path::filename(modulePath));

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2359,8 +2359,9 @@ ModuleDecl *ModuleFile::getModule(ImportPath::Module name,
23592359
return getContext().TheBuiltinModule;
23602360

23612361
// FIXME: duplicated from ImportResolver::getModule
2362+
Identifier parentName = FileContext->getParentModule()->getName();
23622363
if (name.size() == 1 &&
2363-
name.front().Item == FileContext->getParentModule()->getName()) {
2364+
name.front().Item == getContext().getRealModuleName(parentName)) {
23642365
if (!UnderlyingModule && allowLoading) {
23652366
auto importer = getContext().getClangModuleLoader();
23662367
assert(importer && "no way to import shadowed module");

test/ModuleInterface/ambiguous-aliases-workaround.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
// RUN: -alias-module-names-in-module-interface
1919
// RUN: %target-swift-typecheck-module-from-interface(%t/AmbiguousClientName.swiftinterface) -I%t
2020

21+
// RUN: %target-swift-frontend -emit-module -module-name OverlayClient \
22+
// RUN: -swift-version 5 -enable-library-evolution \
23+
// RUN: -o %t/OverlayClient.swiftmodule \
24+
// RUN: -emit-module-interface-path %t/OverlayClient.swiftinterface \
25+
// RUN: %t/OverlayClient.swift -I%t \
26+
// RUN: -alias-module-names-in-module-interface
27+
// RUN: %target-swift-typecheck-module-from-interface(%t/OverlayClient.swiftinterface) -I%t
28+
2129
//--- module.modulemap
2230
module AmbiguousClientName {
2331
header "AmbiguousClientName.h"
@@ -64,3 +72,10 @@ public func refToNestedInLib(_ a: AmbiguousLib.Nested) {}
6472
public func refToStdlib(_ a: Swift.Int) {}
6573
public func refToUnderlying(_ a: UnderlyingType) {}
6674
public func refToC(_ a: CType) {}
75+
76+
//--- OverlayClient.swift
77+
78+
import AmbiguousClientName
79+
80+
public func refToImportedType(_ a: SomeType) {}
81+
public func refToImportedUnderlying(_ a: UnderlyingType) {}

0 commit comments

Comments
 (0)