diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-09-11 15:16:50 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-09-11 15:16:50 -0400 |
| commit | 7dd3c3814de0caf808bc112aa07044cdd8bba135 (patch) | |
| tree | 3ed6db0680f013c496535d447261462129454975 /src/analyze.cpp | |
| parent | dd1338b0e6280b10b9b62ca73bf9ece34bd8524e (diff) | |
| download | zig-7dd3c3814de0caf808bc112aa07044cdd8bba135.tar.gz zig-7dd3c3814de0caf808bc112aa07044cdd8bba135.zip | |
fix incorrect error union const value generation
closes #1442
zig needed to insert explicit padding into this structure before
it got bitcasted.
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index e0539df10b..07c7b94e25 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -5882,12 +5882,23 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { } case ZigTypeIdErrorUnion: { - buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name)); + buf_appendf(buf, "%s(", buf_ptr(&type_entry->name)); + if (const_val->data.x_err_union.err == nullptr) { + render_const_value(g, buf, const_val->data.x_err_union.payload); + } else { + buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->data.error_union.err_set_type->name), + buf_ptr(&const_val->data.x_err_union.err->name)); + } + buf_appendf(buf, ")"); return; } case ZigTypeIdUnion: { - buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name)); + uint64_t tag = bigint_as_unsigned(&const_val->data.x_union.tag); + TypeUnionField *field = &type_entry->data.unionation.fields[tag]; + buf_appendf(buf, "%s { .%s = ", buf_ptr(&type_entry->name), buf_ptr(field->name)); + render_const_value(g, buf, const_val->data.x_union.payload); + buf_append_str(buf, "}"); return; } case ZigTypeIdErrorSet: |
