From 79adf55699a549841eba3eb07f1dbb19c4da9ed1 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 2 Feb 2016 15:58:13 -0700 Subject: [PATCH] fx segfault with colliding bogus top level functions --- src/analyze.cpp | 7 ++++++- test/run_tests.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index 7af8632b96..bf6bcee289 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -5038,7 +5038,12 @@ static void detect_top_level_decl_deps(CodeGen *g, ImportTableEntry *import, Ast decl_node->name = name; decl_node->import = import; if (decl_node->deps.size() > 0) { - g->unresolved_top_level_decls.put(name, node); + if (g->unresolved_top_level_decls.maybe_get(name)) { + node->data.fn_proto.skip = true; + add_node_error(g, node, buf_sprintf("redefinition of '%s'", buf_ptr(name))); + } else { + g->unresolved_top_level_decls.put(name, node); + } } else { resolve_top_level_decl(g, import, node); } diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 7a58668d2d..39bbf504b8 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -1964,6 +1964,14 @@ export fn c(x: i32) -> i32 {x + 2} const x : f64 = 1.0; const y : f32 = x; )SOURCE", 1, ".tmp_source.zig:3:17: error: expected type 'f32', got 'f64'"); + + + add_compile_fail_case("colliding invalid top level functions", R"SOURCE( +fn func() -> bogus {} +fn func() -> bogus {} + )SOURCE", 2, + ".tmp_source.zig:3:1: error: redefinition of 'func'", + ".tmp_source.zig:2:14: error: use of undeclared identifier 'bogus'"); } //////////////////////////////////////////////////////////////////////////////