mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[serialization] Reject loading a module with the wrong case.
Due to case-insensitive filesystems, "import foundation" can result in the overlay module for Foundation being loaded. Everything is confused later on because the (wrong) module name is used in manglings, leading to all sorts of issues. This is not the right fix for the problem, because a user really is allowed to have modules named "foundation" and "FOUNDATION" and "Foundation" coexisting on their system. To do that we'll want to check the actual case of a .framework bundle or .swiftmodule file on disk and make sure it matches before even trying to load the file. But this is a good sanity check anyway. rdar://problem/15632996 Swift SVN r22818
This commit is contained in:
@@ -191,6 +191,7 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
return nullptr;
|
||||
case ModuleStatus::MissingDependency:
|
||||
case ModuleStatus::MissingShadowedModule:
|
||||
case ModuleStatus::NameMismatch:
|
||||
llvm_unreachable("dependencies haven't been loaded yet");
|
||||
}
|
||||
|
||||
@@ -207,12 +208,24 @@ FileUnit *SerializedModuleLoader::loadAST(
|
||||
|
||||
// We failed to bring the module file into the AST.
|
||||
M.removeFile(*fileUnit);
|
||||
assert(loadedModuleFile->getStatus() == ModuleStatus::MissingDependency ||
|
||||
assert(loadedModuleFile->getStatus() == ModuleStatus::NameMismatch ||
|
||||
loadedModuleFile->getStatus() == ModuleStatus::MissingDependency ||
|
||||
loadedModuleFile->getStatus() == ModuleStatus::MissingShadowedModule);
|
||||
|
||||
if (!diagLoc)
|
||||
return nullptr;
|
||||
|
||||
if (loadedModuleFile->getStatus() == ModuleStatus::NameMismatch) {
|
||||
// FIXME: This doesn't handle a non-debugger REPL, which should also treat
|
||||
// this as a non-fatal error.
|
||||
auto diagKind = diag::serialization_name_mismatch;
|
||||
if (Ctx.LangOpts.DebuggerSupport)
|
||||
diagKind = diag::serialization_name_mismatch_repl;
|
||||
Ctx.Diags.diagnose(*diagLoc, diagKind,
|
||||
loadedModuleFile->getModuleName(), M.Name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (loadedModuleFile->getStatus() == ModuleStatus::MissingShadowedModule) {
|
||||
Ctx.Diags.diagnose(*diagLoc, diag::serialization_missing_shadowed_module,
|
||||
M.Name);
|
||||
|
||||
Reference in New Issue
Block a user