mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 00:35:10 +00:00
Merge pull request #1149 from ziglang/issue346
fix compiler crash for invalid enum
This commit is contained in:
commit
be2a4c42bd
@ -2318,8 +2318,9 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (enum_type->data.enumeration.zero_bits_loop_flag) {
|
if (enum_type->data.enumeration.zero_bits_loop_flag) {
|
||||||
enum_type->data.enumeration.zero_bits_known = true;
|
add_node_error(g, enum_type->data.enumeration.decl_node,
|
||||||
enum_type->data.enumeration.zero_bits_loop_flag = false;
|
buf_sprintf("'%s' depends on itself", buf_ptr(&enum_type->name)));
|
||||||
|
enum_type->data.enumeration.is_invalid = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,19 @@
|
|||||||
const tests = @import("tests.zig");
|
const tests = @import("tests.zig");
|
||||||
|
|
||||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
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(
|
cases.add(
|
||||||
"@floatToInt comptime safety",
|
"@floatToInt comptime safety",
|
||||||
\\comptime {
|
\\comptime {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user