From 06f0effb848c6b938e03da8a61e44b3d032380e8 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 26 Jan 2018 15:30:23 -0800 Subject: Fix handling of errors in imported modules (#387) * Fix handling of errors in imported modules - If a semantic error is detected in an imported module, then don't try to generate IR code for it - Also, if a module (transitively) imports itself, then report that as an error - The way I'm checking for this is a bit hacky (I'm adding the module to the map of loaded modules, but in an "unfinished" state, and then using that unfinished state to detect the import of a module already being imported). This isn't a 100% complete solution for any of the related problems, but it improves the user experience for the common case. * Remove #import test. The feature is slated to be removed, so it isn't worth fixing up this test case. --- tests/bugs/import-with-error-extra.slang | 11 +++++++++++ tests/bugs/import-with-error.slang | 11 +++++++++++ tests/bugs/import-with-error.slang.expected | 6 ++++++ 3 files changed, 28 insertions(+) create mode 100644 tests/bugs/import-with-error-extra.slang create mode 100644 tests/bugs/import-with-error.slang create mode 100644 tests/bugs/import-with-error.slang.expected (limited to 'tests/bugs') diff --git a/tests/bugs/import-with-error-extra.slang b/tests/bugs/import-with-error-extra.slang new file mode 100644 index 000000000..259f6b5d1 --- /dev/null +++ b/tests/bugs/import-with-error-extra.slang @@ -0,0 +1,11 @@ +//TEST_IGNORE_FILE: + +// This file exists to be imported. +// +// It contains a semantic error that should lead to compilation failure +// in the module doing the importing. + +void broken() +{ + int a = b; +} diff --git a/tests/bugs/import-with-error.slang b/tests/bugs/import-with-error.slang new file mode 100644 index 000000000..f50bb1adb --- /dev/null +++ b/tests/bugs/import-with-error.slang @@ -0,0 +1,11 @@ +//TEST:SIMPLE:-use-ir + +// Confirm that we correctly issue a diagnostic when +// we `import` a module that has some errors in it. + +import import_with_error_extra; + +void main() +{ + broken(); +} diff --git a/tests/bugs/import-with-error.slang.expected b/tests/bugs/import-with-error.slang.expected new file mode 100644 index 000000000..b71dba0f1 --- /dev/null +++ b/tests/bugs/import-with-error.slang.expected @@ -0,0 +1,6 @@ +result code = -1 +standard error = { +tests/bugs/import-with-error-extra.slang(10): error 30015: undefined identifier 'b'. +} +standard output = { +} -- cgit v1.2.3