commit be2a4c42bdfdbf9130eaeee3ce66085cb862dcd1 (tree)
parent 5f38d6e2e97829ed74f06a96b5d07a2c68516063
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Thu, 21 Jun 2018 21:21:05 -0400
Merge pull request #1149 from ziglang/issue346
fix compiler crash for invalid enum
Diffstat:
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/analyze.cpp b/src/analyze.cpp
@@ -2318,8 +2318,9 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
return;
if (enum_type->data.enumeration.zero_bits_loop_flag) {
- enum_type->data.enumeration.zero_bits_known = true;
- enum_type->data.enumeration.zero_bits_loop_flag = false;
+ add_node_error(g, enum_type->data.enumeration.decl_node,
+ buf_sprintf("'%s' depends on itself", buf_ptr(&enum_type->name)));
+ enum_type->data.enumeration.is_invalid = true;
return;
}
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -2,6 +2,19 @@ const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
+ "enum field value references enum",
+ \\pub const Foo = extern enum {
+ \\ A = Foo.B,
+ \\ C = D,
+ \\};
+ \\export fn entry() void {
+ \\ var s: Foo = Foo.E;
+ \\}
+ ,
+ ".tmp_source.zig:1:17: error: 'Foo' depends on itself",
+ );
+
+ cases.add(
"@floatToInt comptime safety",
\\comptime {
\\ _ = @floatToInt(i8, f32(-129.1));