authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-21 21:21:05-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-06-21 21:21:05-04:00
logbe2a4c42bdfdbf9130eaeee3ce66085cb862dcd1
tree989e276143fcc59055202f234c7d2209b69ab6d5
parent5f38d6e2e97829ed74f06a96b5d07a2c68516063
parent459d72f8736ebd8372b9050c17e5f3bc00092573
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #1149 from ziglang/issue346

fix compiler crash for invalid enum

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) {
23182318 return;
23192319
23202320 if (enum_type->data.enumeration.zero_bits_loop_flag) {
2321 enum_type->data.enumeration.zero_bits_known = true;
2322 enum_type->data.enumeration.zero_bits_loop_flag = false;
2321 add_node_error(g, enum_type->data.enumeration.decl_node,
2322 buf_sprintf("'%s' depends on itself", buf_ptr(&enum_type->name)));
2323 enum_type->data.enumeration.is_invalid = true;
23232324 return;
23242325 }
23252326
test/compile_errors.zig+13
......@@ -1,6 +1,19 @@
11const tests = @import("tests.zig");
22
33pub 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
417 cases.add(
518 "@floatToInt comptime safety",
619 \\comptime {