aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/access_inactive_union_field_comptime.zig
blob: d353526d621841015feef09d3f7ad0c81094038b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const Enum = enum(u32) { b, a };
const TaggedUnion = union(Enum) {
    b: []const u8,
    a: []const u8,
};
pub export fn entry() void {
    const result = TaggedUnion{ .b = "b" };
    _ = result.b;
    _ = result.a;
}
pub export fn entry1() void {
    const result = TaggedUnion{ .b = "b" };
    _ = &result.b;
    _ = &result.a;
}

// error
//
// :9:15: error: access of union field 'a' while field 'b' is active
// :2:21: note: union declared here
// :14:16: error: access of union field 'a' while field 'b' is active
// :2:21: note: union declared here