aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/incompatible sub-byte fields.zig
blob: 20fbf5e30c3838896fe08f828bfc4b34581dbbcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const A = packed struct {
    a: u2,
    b: u6,
};
const B = packed struct {
    q: u8,
    a: u2,
    b: u6,
};
export fn entry() void {
    var a = A{ .a = 2, .b = 2 };
    var b = B{ .q = 22, .a = 3, .b = 2 };
    var t: usize = 0;
    const ptr = switch (t) {
        0 => &a.a,
        1 => &b.a,
        else => unreachable,
    };
    if (ptr.* == 2) {
        @compileError("wrong compile error");
    }
}
// error
// backend=stage2
// target=native
//
// :14:17: error: incompatible types: '*align(0:0:1) u2' and '*align(2:8:2) u2'