zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit fc956fc1107e7f7fecec75d178ed315e5f338e12 (tree)
parent c34e9c73aba671e7d79117d29c06a66ae24367c5
Author: Matthew Borkowski <matthew.h.borkowski@gmail.com>
Date:   Sat,  5 Jun 2021 17:22:08 -0400

stage1: fix render_const_value for printing const optional pointers

Diffstat:
Msrc/stage1/analyze.cpp | 10+++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp @@ -7588,8 +7588,16 @@ void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) { } case ZigTypeIdOptional: { - if (get_src_ptr_type(const_val->type) != nullptr) + ZigType *src_ptr_type = get_src_ptr_type(const_val->type); + if (src_ptr_type != nullptr) { + if (src_ptr_type->id == ZigTypeIdPointer && !optional_value_is_null(const_val)) { + ZigValue tmp = {}; + copy_const_val(g, &tmp, const_val); + tmp.type = type_entry->data.maybe.child_type; + return render_const_val_ptr(g, buf, &tmp, tmp.type); + } return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type); + } if (type_entry->data.maybe.child_type->id == ZigTypeIdErrorSet) return render_const_val_err_set(g, buf, const_val, type_entry->data.maybe.child_type); if (const_val->data.x_optional) {