aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/analyze.cpp6
-rw-r--r--test/stage1/behavior/type_info.zig8
2 files changed, 14 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 542fbb56ce..699b121276 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -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);
diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig
index 41301f290d..68ff3aa310 100644
--- a/test/stage1/behavior/type_info.zig
+++ b/test/stage1/behavior/type_info.zig
@@ -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);
+ }
+}