authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-10 00:03:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-10 00:03:31-07:00
log49d0971cd4f6aa3f897a0f36272c05c641e25f79
tree38a52e168cbcf30efddb4b01f4431b4e5c19a30a
parent1fe1235e14cd599c1b3a6f079670b7cb7ea270d2

detect and report top level decl dependency loop


4 files changed, 26 insertions(+), 9 deletions(-)

src/analyze.cpp+3-1
......@@ -3033,7 +3033,9 @@ static void recursive_resolve_decl(CodeGen *g, ImportTableEntry *import, AstNode
30333033 AstNode *child_node = unresolved_entry->value;
30343034
30353035 if (child_node->codegen_node->decl_node.in_current_deps) {
3036 zig_panic("TODO infinite top level decl loop");
3036 // dependency loop. we'll let the fact that it's not in the respective
3037 // table cause an error in resolve_top_level_decl.
3038 continue;
30373039 }
30383040
30393041 // set temporary flag
std/rand.zig+2-4
......@@ -3,10 +3,8 @@ const ARRAY_SIZE : u16 = 624;
33
44/// Use `rand_init` to initialize this state.
55pub struct Rand {
6 // TODO use ARRAY_SIZE here
7 array: [624]u32,
8 // TODO use #typeof(ARRAY_SIZE) here
9 index: u16,
6 array: [ARRAY_SIZE]u32,
7 index: #typeof(ARRAY_SIZE),
108
119 /// Initialize random state with the given seed.
1210 pub fn init(r: &Rand, seed: u32) {
std/std.zig+2-4
......@@ -24,8 +24,7 @@ pub fn fprint_str(fd: isize, str: []const u8) -> isize {
2424// TODO handle buffering and flushing (mutex protected)
2525// TODO error handling
2626pub fn print_u64(x: u64) -> isize {
27 // TODO use max_u64_base10_digits instead of hardcoding 20
28 var buf: [20]u8;
27 var buf: [max_u64_base10_digits]u8;
2928 const len = buf_print_u64(buf, x);
3029 return write(stdout_fileno, buf.ptr, len);
3130}
......@@ -33,8 +32,7 @@ pub fn print_u64(x: u64) -> isize {
3332// TODO handle buffering and flushing (mutex protected)
3433// TODO error handling
3534pub fn print_i64(x: i64) -> isize {
36 // TODO use max_u64_base10_digits instead of hardcoding 20
37 var buf: [20]u8;
35 var buf: [max_u64_base10_digits]u8;
3836 const len = buf_print_i64(buf, x);
3937 return write(stdout_fileno, buf.ptr, len);
4038}
test/run_tests.cpp+19
......@@ -991,6 +991,20 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
991991 return 0;
992992}
993993 )SOURCE", "OK\n");
994
995 add_simple_case("order-independent declarations", R"SOURCE(
996use "std.zig";
997const x : #typeof(y) = 1234;
998const y : u16 = 5678;
999pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
1000 print_ok(x)
1001}
1002fn print_ok(val: #typeof(x)) -> #typeof(foo) {
1003 print_str("OK\n");
1004 return 0;
1005}
1006const foo : i32 = 0;
1007 )SOURCE", "OK\n");
9941008}
9951009
9961010
......@@ -1299,6 +1313,11 @@ fn f() -> i32 {
12991313fn f() -> #bogus(foo) {
13001314}
13011315 )SOURCE", 1, ".tmp_source.zig:2:11: error: invalid compiler function: 'bogus'");
1316
1317 add_compile_fail_case("top level decl dependency loop", R"SOURCE(
1318const a : #typeof(b) = 0;
1319const b : #typeof(a) = 0;
1320 )SOURCE", 1, ".tmp_source.zig:3:19: error: use of undeclared identifier 'a'");
13021321}
13031322
13041323static void print_compiler_invocation(TestCase *test_case) {