diff options
Diffstat (limited to 'lang/zig/unreachable.zig')
-rw-r--r-- | lang/zig/unreachable.zig | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lang/zig/unreachable.zig b/lang/zig/unreachable.zig new file mode 100644 index 0000000..26463a9 --- /dev/null +++ b/lang/zig/unreachable.zig @@ -0,0 +1,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); +} |