mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ScanDependencies] Make sure canImport resolution agrees with import
Fix the problem that when the only module can be found is an invalid/out-of-date swift binary module, canImport and import statement can have different view for if the module can be imported or not. Now canImport will evaluate to false if the only module can be found for name is an invalid swiftmodule, with a warning with the path to the module so users will not be surprised by such behavior. rdar://128876895
This commit is contained in:
@@ -2385,7 +2385,7 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
|
||||
}
|
||||
|
||||
bool ExplicitSwiftModuleLoader::canImportModule(
|
||||
ImportPath::Module path, ModuleVersionInfo *versionInfo,
|
||||
ImportPath::Module path, SourceLoc loc, ModuleVersionInfo *versionInfo,
|
||||
bool isTestableDependencyLookup) {
|
||||
// FIXME: Swift submodules?
|
||||
if (path.hasSubmodule())
|
||||
@@ -2411,7 +2411,7 @@ bool ExplicitSwiftModuleLoader::canImportModule(
|
||||
auto &fs = *Ctx.SourceMgr.getFileSystem();
|
||||
auto moduleBuf = fs.getBufferForFile(it->second.modulePath);
|
||||
if (!moduleBuf) {
|
||||
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
|
||||
Ctx.Diags.diagnose(loc, diag::error_opening_explicit_module_file,
|
||||
it->second.modulePath);
|
||||
return false;
|
||||
}
|
||||
@@ -2422,8 +2422,7 @@ bool ExplicitSwiftModuleLoader::canImportModule(
|
||||
if (auto forwardingModule = ForwardingModule::load(**moduleBuf)) {
|
||||
moduleBuf = fs.getBufferForFile(forwardingModule->underlyingModulePath);
|
||||
if (!moduleBuf) {
|
||||
Ctx.Diags.diagnose(SourceLoc(),
|
||||
diag::error_opening_explicit_module_file,
|
||||
Ctx.Diags.diagnose(loc, diag::error_opening_explicit_module_file,
|
||||
forwardingModule->underlyingModulePath);
|
||||
return false;
|
||||
}
|
||||
@@ -2736,7 +2735,7 @@ std::error_code ExplicitCASModuleLoader::findModuleFilesInDirectory(
|
||||
}
|
||||
|
||||
bool ExplicitCASModuleLoader::canImportModule(
|
||||
ImportPath::Module path, ModuleVersionInfo *versionInfo,
|
||||
ImportPath::Module path, SourceLoc loc, ModuleVersionInfo *versionInfo,
|
||||
bool isTestableDependencyLookup) {
|
||||
// FIXME: Swift submodules?
|
||||
if (path.hasSubmodule())
|
||||
@@ -2765,12 +2764,11 @@ bool ExplicitCASModuleLoader::canImportModule(
|
||||
: it->second.modulePath;
|
||||
auto moduleBuf = Impl.loadFileBuffer(moduleCASID, it->second.modulePath);
|
||||
if (!moduleBuf) {
|
||||
Ctx.Diags.diagnose(SourceLoc(), diag::error_cas,
|
||||
toString(moduleBuf.takeError()));
|
||||
Ctx.Diags.diagnose(loc, diag::error_cas, toString(moduleBuf.takeError()));
|
||||
return false;
|
||||
}
|
||||
if (!*moduleBuf) {
|
||||
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
|
||||
Ctx.Diags.diagnose(loc, diag::error_opening_explicit_module_file,
|
||||
it->second.modulePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user