Skip to content

Commit 21b733b

Browse files
committed
[Frontend] Set "failed to load" for failed partial module
If a partial module fails to load, the main module may be left without files, so let's set the failed to load bit.
1 parent 898f980 commit 21b733b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,12 @@ void CompilerInstance::performSemaUpTo(SourceFile::ASTStage_t LimitStage,
761761
// If we aren't in a parse-only context, load the remaining serialized inputs
762762
// and resolve implicit imports.
763763
if (LimitStage > SourceFile::Unprocessed &&
764-
loadPartialModulesAndImplicitImports())
764+
loadPartialModulesAndImplicitImports()) {
765+
// If we failed to load a partial module, mark the main module as having
766+
// "failed to load", as it may contain no files.
767+
mainModule->setFailedToLoad();
765768
return;
769+
}
766770

767771
// Then parse all the input files.
768772
// FIXME: This is the only demand point for InputSourceCodeBufferIDs. We
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// Make sure we don't crash if we fail to load a partial module.
4+
// RUN: %target-swift-frontend -emit-module -primary-file %s -module-name A -o %t/a.partial.swiftmodule
5+
// RUN: not %target-swift-frontend -emit-module -merge-modules %t/a.partial.swiftmodule -module-name Unrelated 2>&1 | %FileCheck %s
6+
7+
// CHECK: error: cannot load module 'A' as 'Unrelated'

0 commit comments

Comments
 (0)