Skip to content

Commit 129a4fb

Browse files
alexnaskandrewrk
authored andcommitted
Copy union const values correctly
1 parent 2c7fc1c commit 129a4fb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/analyze.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9597,6 +9597,12 @@ void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src) {
95979597
break;
95989598
}
95999599
}
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;
96009606
} else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {
96019607
dest->data.x_optional = g->pass1_arena->create<ZigValue>();
96029608
copy_const_val(g, dest->data.x_optional, src->data.x_optional);

test/stage1/behavior/type_info.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,11 @@ test "type info for async frames" {
402402
else => unreachable,
403403
}
404404
}
405+
406+
test "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+
}

0 commit comments

Comments
 (0)