aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig
blob: a6f10668b628fab7b71ee06ce9ca107960ff4686 (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
const E = enum(u8) {
    a,
    b,
    _,
};
const U = union(E) {
    a,
    b,
};
export fn foo() void {
    var e: E = @enumFromInt(15);
    var u: U = e;
    _ = .{ &e, &u };
}
export fn bar() void {
    const e: E = @enumFromInt(15);
    var u: U = e;
    _ = &u;
}

// error
//
// :12:16: error: runtime coercion to union 'tmp.U' from non-exhaustive enum
// :1:11: note: enum declared here
// :17:16: error: union 'tmp.U' has no tag with value '@enumFromInt(15)'
// :6:11: note: union declared here