authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-02-19 21:18:57+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-19 15:18:57-05:00
log400006bbe790f2173fd6e40d80608691a95b437e
tree42d980d1b064c0efd1f8aa602e03994f811129e3
parentdb74832e40f98960e5dc3e46c8196c59033ee0f9

Prevent crash in tagged enums rendering (#1986)

* Prevent crash in tagged enums rendering * Add a test case

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

src/analyze.cpp+2-2
......@@ -6276,8 +6276,8 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
62766276 }
62776277 case ZigTypeIdUnion:
62786278 {
6279 uint64_t tag = bigint_as_unsigned(&const_val->data.x_union.tag);
6280 TypeUnionField *field = &type_entry->data.unionation.fields[tag];
6279 const BigInt *tag = &const_val->data.x_union.tag;
6280 TypeUnionField *field = find_union_field_by_tag(type_entry, tag);
62816281 buf_appendf(buf, "%s { .%s = ", buf_ptr(&type_entry->name), buf_ptr(field->name));
62826282 render_const_value(g, buf, const_val->data.x_union.payload);
62836283 buf_append_str(buf, "}");
test/compile_errors.zig+17
......@@ -5599,4 +5599,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
55995599 ,
56005600 ".tmp_source.zig:2:26: error: vector element type must be integer, float, or pointer; '@Vector(4, u8)' is invalid",
56015601 );
5602
5603 cases.add(
5604 "compileLog of tagged enum doesn't crash the compiler",
5605 \\const Bar = union(enum(u32)) {
5606 \\ X: i32 = 1
5607 \\};
5608 \\
5609 \\fn testCompileLog(x: Bar) void {
5610 \\ @compileLog(x);
5611 \\}
5612 \\
5613 \\pub fn main () void {
5614 \\ comptime testCompileLog(Bar{.X = 123});
5615 \\}
5616 ,
5617 ".tmp_source.zig:6:5: error: found compile log statement"
5618 );
56025619}