authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-10-10 10:47:59+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-10 13:57:48-04:00
log6cbb732b59d1ded92c7272a8b06f645e1c8acfd2
tree2e8e256c26ffd1bc2c7d58850588696ee4b9f857
parent4e81df12c3dae2ae67ef25fcfe65e8db724e84f3

Extern unions should not trigger active field check

Fixes #3378

2 files changed, 11 insertions(+), 1 deletions(-)

src/ir.cpp+1-1
......@@ -17951,7 +17951,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1795117951 union_val->special = ConstValSpecialStatic;
1795217952 bigint_init_bigint(&union_val->data.x_union.tag, &field->enum_field->value);
1795317953 union_val->data.x_union.payload = payload_val;
17954 } else {
17954 } else if (bare_type->data.unionation.layout != ContainerLayoutExtern) {
1795517955 TypeUnionField *actual_field = find_union_field_by_tag(bare_type, &union_val->data.x_union.tag);
1795617956 if (actual_field == nullptr)
1795717957 zig_unreachable();
test/stage1/behavior/union.zig+10
......@@ -511,3 +511,13 @@ test "union with comptime_int tag" {
511511 };
512512 comptime expect(@TagType(@TagType(Union)) == comptime_int);
513513}
514
515test "extern union doesn't trigger field check at comptime" {
516 const U = extern union {
517 x: u32,
518 y: u8,
519 };
520
521 const x = U{ .x = 0x55AAAA55 };
522 comptime expect(x.y == 0x55);
523}