mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #40777 from ApolloZhu/fix-canImport-submodule-checking
Fix canImport submodule checking in loaders not supporting submodules
This commit is contained in:
@@ -1867,6 +1867,8 @@ bool ExplicitSwiftModuleLoader::canImportModule(ImportPath::Module path,
|
||||
llvm::VersionTuple version,
|
||||
bool underlyingVersion) {
|
||||
// FIXME: Swift submodules?
|
||||
if (path.hasSubmodule())
|
||||
return false;
|
||||
ImportPath::Element mID = path.front();
|
||||
// Look up the module with the real name (physical name on disk);
|
||||
// in case `-module-alias` is used, the name appearing in source files
|
||||
|
||||
@@ -73,7 +73,7 @@ bool SourceLoader::canImportModule(ImportPath::Module path,
|
||||
llvm::VersionTuple version,
|
||||
bool underlyingVersion) {
|
||||
// FIXME: Swift submodules?
|
||||
if (path.size() > 1)
|
||||
if (path.hasSubmodule())
|
||||
return false;
|
||||
|
||||
auto ID = path[0];
|
||||
|
||||
@@ -1133,6 +1133,9 @@ swift::extractUserModuleVersionFromInterface(StringRef moduleInterfacePath) {
|
||||
bool SerializedModuleLoaderBase::canImportModule(ImportPath::Module path,
|
||||
llvm::VersionTuple version,
|
||||
bool underlyingVersion) {
|
||||
// FIXME: Swift submodules?
|
||||
if (path.hasSubmodule())
|
||||
return false;
|
||||
// If underlying version is specified, this should be handled by Clang importer.
|
||||
if (!version.empty() && underlyingVersion)
|
||||
return false;
|
||||
@@ -1153,7 +1156,6 @@ bool SerializedModuleLoaderBase::canImportModule(ImportPath::Module path,
|
||||
unusedModuleDocBuffer = &moduleDocBuffer;
|
||||
}
|
||||
|
||||
// FIXME: Swift submodules?
|
||||
auto mID = path[0];
|
||||
auto found = findModule(mID, unusedModuleInterfacePath, unusedModuleBuffer,
|
||||
unusedModuleDocBuffer, unusedModuleSourceInfoBuffer,
|
||||
@@ -1193,10 +1195,12 @@ bool SerializedModuleLoaderBase::canImportModule(ImportPath::Module path,
|
||||
bool MemoryBufferSerializedModuleLoader::canImportModule(
|
||||
ImportPath::Module path, llvm::VersionTuple version,
|
||||
bool underlyingVersion) {
|
||||
// FIXME: Swift submodules?
|
||||
if (path.hasSubmodule())
|
||||
return false;
|
||||
// If underlying version is specified, this should be handled by Clang importer.
|
||||
if (!version.empty() && underlyingVersion)
|
||||
return false;
|
||||
// FIXME: Swift submodules?
|
||||
auto mID = path[0];
|
||||
auto mIt = MemoryBuffers.find(mID.Item.str());
|
||||
if (mIt == MemoryBuffers.end())
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
int fromSubmodule;
|
||||
@@ -0,0 +1,6 @@
|
||||
framework module WithSubmodule {
|
||||
explicit module Submodule {
|
||||
header "Submodule.h"
|
||||
export *
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: cp -r %S/Inputs/WithSubmodule.framework %t
|
||||
// RUN: %target-swift-frontend -emit-module -o %t/WithSubmodule.framework/Modules/WithSubmodule.swiftmodule/%target-swiftmodule-name %t/WithSubmodule.framework/Empty.swift -import-underlying-module -F %t -module-name WithSubmodule
|
||||
|
||||
// RUN: %target-typecheck-verify-swift -F %t
|
||||
|
||||
// Testing 'canImport()' non-existing submodule in a top module loadable by other loaders.
|
||||
|
||||
#if !canImport(WithSubmodule.Submodule)
|
||||
#error("Should can import WithSubmodule.Submodule")
|
||||
#endif
|
||||
|
||||
// Should fail if checked for a non-existing submodule.
|
||||
#if canImport(WithSubmodule.ButNotMe)
|
||||
import WithSubmodule.Submodule
|
||||
#endif
|
||||
|
||||
func testNotImported() {
|
||||
fromSubmodule = 5
|
||||
// expected-error@-1 {{cannot find 'fromSubmodule' in scope}}
|
||||
}
|
||||
Reference in New Issue
Block a user