summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2018-03-12 14:02:28 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2018-03-12 11:02:28 -0700
commite08f0c6ea0552a2d626294c718cd4409f437ba10 (patch)
treeeea41576e8422bf9e299227328b5e326ce90dafd
parent51bc468959b5ab8103c196adaabcafdb5d0b3feb (diff)
Stop compilation when a imported module contains errors. (#440)
* Stop compilation when a important module contains errors. * Fixup test cases
-rw-r--r--source/slang/diagnostic-defs.h1
-rw-r--r--source/slang/slang.cpp14
-rw-r--r--tests/bugs/import-with-error.slang.expected1
-rw-r--r--tests/diagnostics/recursive-import.slang.expected1
4 files changed, 15 insertions, 2 deletions
diff --git a/source/slang/diagnostic-defs.h b/source/slang/diagnostic-defs.h
index 14efdb9a9..220ad44ff 100644
--- a/source/slang/diagnostic-defs.h
+++ b/source/slang/diagnostic-defs.h
@@ -273,6 +273,7 @@ DIAGNOSTIC(38020, Error, mismatchEntryPointTypeArgument, "expecting $0 entry-poi
DIAGNOSTIC(38021, Error, typeArgumentDoesNotConformToInterface, "type argument `$1` for generic parameter `$0` does not conform to interface `$1`.")
DIAGNOSTIC(38200, Error, recursiveModuleImport, "module `$0` recursively imports itself")
+DIAGNOSTIC(39999, Fatal, errorInImportedModule, "error in imported module, compilation ceased.")
//
// 4xxxx - IL code generation.
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index f2e5587fa..1d888dcb5 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -526,9 +526,9 @@ void CompileRequest::loadParsedModule(
{
// If we didn't run into any errors, then try to generate
// IR code for the imported module.
+ SLANG_ASSERT(errorCountAfter == 0);
loadedModule->irModule = generateIRForTranslationUnit(translationUnit);
}
-
loadedModulesList.Add(loadedModule);
}
@@ -536,7 +536,7 @@ RefPtr<ModuleDecl> CompileRequest::loadModule(
Name* name,
String const& path,
String const& source,
- SourceLoc const&)
+ SourceLoc const& srcLoc)
{
RefPtr<TranslationUnitRequest> translationUnit = new TranslationUnitRequest();
translationUnit->compileRequest = this;
@@ -559,6 +559,7 @@ RefPtr<ModuleDecl> CompileRequest::loadModule(
if( errorCountAfter != errorCountBefore )
{
+ mSink.diagnose(srcLoc, Diagnostics::errorInImportedModule);
// Something went wrong during the parsing, so we should bail out.
return nullptr;
}
@@ -568,6 +569,15 @@ RefPtr<ModuleDecl> CompileRequest::loadModule(
name,
path);
+ errorCountAfter = mSink.GetErrorCount();
+
+ if (errorCountAfter != errorCountBefore)
+ {
+ mSink.diagnose(srcLoc, Diagnostics::errorInImportedModule);
+ // Something went wrong during the parsing, so we should bail out.
+ return nullptr;
+ }
+
return translationUnit->SyntaxNode;
}
diff --git a/tests/bugs/import-with-error.slang.expected b/tests/bugs/import-with-error.slang.expected
index b71dba0f1..3a70095c3 100644
--- a/tests/bugs/import-with-error.slang.expected
+++ b/tests/bugs/import-with-error.slang.expected
@@ -1,6 +1,7 @@
result code = -1
standard error = {
tests/bugs/import-with-error-extra.slang(10): error 30015: undefined identifier 'b'.
+tests/bugs/import-with-error.slang(6): fatal error 39999: error in imported module, compilation ceased.
}
standard output = {
}
diff --git a/tests/diagnostics/recursive-import.slang.expected b/tests/diagnostics/recursive-import.slang.expected
index ad5cf1975..655c328d5 100644
--- a/tests/diagnostics/recursive-import.slang.expected
+++ b/tests/diagnostics/recursive-import.slang.expected
@@ -1,6 +1,7 @@
result code = -1
standard error = {
tests/diagnostics/recursive-import.slang(6): error 38200: module `recursive_import_extra` recursively imports itself
+tests/diagnostics/recursive-import-extra.slang(6): fatal error 39999: error in imported module, compilation ceased.
}
standard output = {
}