| author | |
| committer | |
| log | 400006bbe790f2173fd6e40d80608691a95b437e |
| tree | 42d980d1b064c0efd1f8aa602e03994f811129e3 |
| parent | db74832e40f98960e5dc3e46c8196c59033ee0f9 |
* 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) { |
| 6276 | 6276 | } |
| 6277 | 6277 | case ZigTypeIdUnion: |
| 6278 | 6278 | { |
| 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); | |
| 6281 | 6281 | buf_appendf(buf, "%s { .%s = ", buf_ptr(&type_entry->name), buf_ptr(field->name)); |
| 6282 | 6282 | render_const_value(g, buf, const_val->data.x_union.payload); |
| 6283 | 6283 | buf_append_str(buf, "}"); |
test/compile_errors.zig+17| ... | ... | @@ -5599,4 +5599,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5599 | 5599 | , |
| 5600 | 5600 | ".tmp_source.zig:2:26: error: vector element type must be integer, float, or pointer; '@Vector(4, u8)' is invalid", |
| 5601 | 5601 | ); |
| 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 | ); | |
| 5602 | 5619 | } |