authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-02 00:59:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-12-02 00:59:58-07:00
loge94681b9618eafbdd23d8b1416fc536fc81debbc
tree06569e4f9f2a60061b28bda2bfb349eaab59ec68
parent370de7386ce811b6381c3ffcf5dd8efd2810da2b

add test for undeclared identifier error


2 files changed, 11 insertions(+), 2 deletions(-)

src/codegen.cpp+1-1
...@@ -821,7 +821,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou...@@ -821,7 +821,7 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *source_path, Buf *sou
821 Buf *import_code = buf_alloc();821 Buf *import_code = buf_alloc();
822 if ((err = os_fetch_file_path(&full_path, import_code))) {822 if ((err = os_fetch_file_path(&full_path, import_code))) {
823 add_node_error(g, top_level_decl,823 add_node_error(g, top_level_decl,
824 buf_sprintf("unable to open \"%s\": %s", buf_ptr(&full_path), err_str(err)));824 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
825 break;825 break;
826 }826 }
827 codegen_add_code(g, &top_level_decl->data.use.path, import_code);827 codegen_add_code(g, &top_level_decl->data.use.path, import_code);
test/run_tests.cpp+10-1
...@@ -295,7 +295,16 @@ export executable "test";...@@ -295,7 +295,16 @@ export executable "test";
295295
296 add_compile_fail_case("bad import", R"SOURCE(296 add_compile_fail_case("bad import", R"SOURCE(
297use "bogus-does-not-exist.zig";297use "bogus-does-not-exist.zig";
298 )SOURCE", 1, ".tmp_source.zig:2:1: error: unable to open \"./bogus-does-not-exist.zig\": file not found");298 )SOURCE", 1, ".tmp_source.zig:2:1: error: unable to open './bogus-does-not-exist.zig': file not found");
299
300 add_compile_fail_case("undeclared identifier", R"SOURCE(
301fn a() {
302 b +
303 c
304}
305 )SOURCE", 2,
306 ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'",
307 ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'");
299}308}
300309
301static void print_compiler_invokation(TestCase *test_case, Buf *zig_stderr) {310static void print_compiler_invokation(TestCase *test_case, Buf *zig_stderr) {