Skip to content

Commit 439c148

Browse files
committed
Assert that an added file loaded without error
1 parent 046f17f commit 439c148

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

include/swift/AST/FileUnit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ class LoadedFile : public FileUnit {
384384

385385
virtual bool isSystemModule() const { return false; }
386386

387+
/// Checks whether an error was encountered while loading the file.
388+
virtual bool hadLoadError() const { return false; }
389+
387390
/// Retrieve the set of generic signatures stored within this module.
388391
///
389392
/// \returns \c true if this module file supports retrieving all of the

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ class SerializedASTFile final : public LoadedFile {
322322
/// file.
323323
const version::Version &getLanguageVersionBuiltWith() const;
324324

325+
virtual bool hadLoadError() const override;
326+
325327
virtual bool isSystemModule() const override;
326328

327329
virtual void lookupValue(DeclName name, NLKind lookupKind,

lib/AST/Module.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ bool ModuleDecl::isClangModule() const {
498498
}
499499

500500
void ModuleDecl::addFile(FileUnit &newFile) {
501+
// If this is a LoadedFile, make sure it loaded without error.
502+
assert(!(isa<LoadedFile>(newFile) &&
503+
cast<LoadedFile>(newFile).hadLoadError()));
504+
501505
// Require Main and REPL files to be the first file added.
502506
assert(Files.empty() ||
503507
!isa<SourceFile>(newFile) ||

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,10 @@ bool SerializedASTFile::isSIB() const {
11031103
return File.IsSIB;
11041104
}
11051105

1106+
bool SerializedASTFile::hadLoadError() const {
1107+
return File.hasError();
1108+
}
1109+
11061110
bool SerializedASTFile::isSystemModule() const {
11071111
if (auto Mod = File.getUnderlyingModule()) {
11081112
return Mod->isSystemModule();

0 commit comments

Comments
 (0)