about summary refs log tree commit diff
path: root/lang/zig/unreachable.zig
blob: 26463a989041b74adbff231b7de221ce1cb06452 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
test "basic math" {
    const x = 1;
    const y = 2;
    if (x + y != 3)
        unreachable;
}

fn assert(ok: bool) void {
    if (!ok) unreachable; // assertion failure
}

// This test will fail because we hit unreachable.
test "this will fail" {
    assert(false);
}

// The type of unreachable is noreturn.
test "type of unreachable" {
    // However this assertion will still fail because
    // evaluating unreachable at compile-time is a compile error.
    comptime assert(@TypeOf(unreachable) == noreturn);
}