authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-06-24 20:00:11+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-24 15:21:58-04:00
log129a4fb251f8eab22eacf219fbf81006baec3251
tree046e4e1ee4ec228366d43a3fdda7762aedda274b
parent2c7fc1c5c504af9dd22d5ac21ecc6773e263e395

Copy union const values correctly


2 files changed, 14 insertions(+), 0 deletions(-)

src/analyze.cpp+6
...@@ -9597,6 +9597,12 @@ void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src) {...@@ -9597,6 +9597,12 @@ void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src) {
9597 break;9597 break;
9598 }9598 }
9599 }9599 }
9600 } else if (dest->type->id == ZigTypeIdUnion) {
9601 bigint_init_bigint(&dest->data.x_union.tag, &src->data.x_union.tag);
9602 dest->data.x_union.payload = g->pass1_arena->create<ZigValue>();
9603 copy_const_val(g, dest->data.x_union.payload, src->data.x_union.payload);
9604 dest->data.x_union.payload->parent.id = ConstParentIdUnion;
9605 dest->data.x_union.payload->parent.data.p_union.union_val = dest;
9600 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {9606 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {
9601 dest->data.x_optional = g->pass1_arena->create<ZigValue>();9607 dest->data.x_optional = g->pass1_arena->create<ZigValue>();
9602 copy_const_val(g, dest->data.x_optional, src->data.x_optional);9608 copy_const_val(g, dest->data.x_optional, src->data.x_optional);
test/stage1/behavior/type_info.zig+8
...@@ -402,3 +402,11 @@ test "type info for async frames" {...@@ -402,3 +402,11 @@ test "type info for async frames" {
402 else => unreachable,402 else => unreachable,
403 }403 }
404}404}
405
406test "type info: value is correctly copied" {
407 comptime {
408 var ptrInfo = @typeInfo([]u32);
409 ptrInfo.Pointer.size = .One;
410 expect(@typeInfo([]u32).Pointer.size == .Slice);
411 }
412}