mirror of
https://github.com/ziglang/zig.git
synced 2025-12-30 01:53:16 +00:00
parent
4e81df12c3
commit
6cbb732b59
@ -17951,7 +17951,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
|
||||
union_val->special = ConstValSpecialStatic;
|
||||
bigint_init_bigint(&union_val->data.x_union.tag, &field->enum_field->value);
|
||||
union_val->data.x_union.payload = payload_val;
|
||||
} else {
|
||||
} else if (bare_type->data.unionation.layout != ContainerLayoutExtern) {
|
||||
TypeUnionField *actual_field = find_union_field_by_tag(bare_type, &union_val->data.x_union.tag);
|
||||
if (actual_field == nullptr)
|
||||
zig_unreachable();
|
||||
|
||||
@ -511,3 +511,13 @@ test "union with comptime_int tag" {
|
||||
};
|
||||
comptime expect(@TagType(@TagType(Union)) == comptime_int);
|
||||
}
|
||||
|
||||
test "extern union doesn't trigger field check at comptime" {
|
||||
const U = extern union {
|
||||
x: u32,
|
||||
y: u8,
|
||||
};
|
||||
|
||||
const x = U{ .x = 0x55AAAA55 };
|
||||
comptime expect(x.y == 0x55);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user