authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-21 17:41:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-21 17:41:49-04:00
log459d72f8736ebd8372b9050c17e5f3bc00092573
tree989e276143fcc59055202f234c7d2209b69ab6d5
parent5f38d6e2e97829ed74f06a96b5d07a2c68516063

fix compiler crash for invalid enum

closes #1079 closes #1147

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

src/analyze.cpp+3-2
...@@ -2318,8 +2318,9 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {...@@ -2318,8 +2318,9 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
2318 return;2318 return;
23192319
2320 if (enum_type->data.enumeration.zero_bits_loop_flag) {2320 if (enum_type->data.enumeration.zero_bits_loop_flag) {
2321 enum_type->data.enumeration.zero_bits_known = true;2321 add_node_error(g, enum_type->data.enumeration.decl_node,
2322 enum_type->data.enumeration.zero_bits_loop_flag = false;2322 buf_sprintf("'%s' depends on itself", buf_ptr(&enum_type->name)));
2323 enum_type->data.enumeration.is_invalid = true;
2323 return;2324 return;
2324 }2325 }
23252326
test/compile_errors.zig+13
...@@ -1,6 +1,19 @@...@@ -1,6 +1,19 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "enum field value references enum",
6 \\pub const Foo = extern enum {
7 \\ A = Foo.B,
8 \\ C = D,
9 \\};
10 \\export fn entry() void {
11 \\ var s: Foo = Foo.E;
12 \\}
13 ,
14 ".tmp_source.zig:1:17: error: 'Foo' depends on itself",
15 );
16
4 cases.add(17 cases.add(
5 "@floatToInt comptime safety",18 "@floatToInt comptime safety",
6 \\comptime {19 \\comptime {