Copy union const values correctly

master
Alexandros Naskos 2020-06-24 20:00:11 +03:00 committed by Andrew Kelley
parent 2c7fc1c5c5
commit 129a4fb251
2 changed files with 14 additions and 0 deletions

View File

@ -9597,6 +9597,12 @@ void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src) {
break;
}
}
} else if (dest->type->id == ZigTypeIdUnion) {
bigint_init_bigint(&dest->data.x_union.tag, &src->data.x_union.tag);
dest->data.x_union.payload = g->pass1_arena->create<ZigValue>();
copy_const_val(g, dest->data.x_union.payload, src->data.x_union.payload);
dest->data.x_union.payload->parent.id = ConstParentIdUnion;
dest->data.x_union.payload->parent.data.p_union.union_val = dest;
} else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {
dest->data.x_optional = g->pass1_arena->create<ZigValue>();
copy_const_val(g, dest->data.x_optional, src->data.x_optional);

View File

@ -402,3 +402,11 @@ test "type info for async frames" {
else => unreachable,
}
}
test "type info: value is correctly copied" {
comptime {
var ptrInfo = @typeInfo([]u32);
ptrInfo.Pointer.size = .One;
expect(@typeInfo([]u32).Pointer.size == .Slice);
}
}