Commit 129a4fb251

Alexandros Naskos <alex_naskos@hotmail.com>
2020-06-24 19:00:11
Copy union const values correctly
1 parent 2c7fc1c
Changed files (2)
src
test
stage1
behavior
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);
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);
+    }
+}