unreachable
In ReleaseFast
mode, the optimizer uses the assumption that unreachable
code will never be hit to perform optimizations. However, zig test
even in ReleaseFast
mode still emits unreachable
as calls to panic
.
$ zig test test.zig
All tests passed.
In fact, this is how assert is implemented:
$ zig test test.zig
Test 1/1 this will fail...reached unreachable code
/home/andy/dev/zig/docgen_tmp/test.zig:2:14: 0x20424c in ??? (test)
if (!ok) unreachable; // assertion failure
^
assert(false);
^
/home/andy/dev/zig/build/lib/zig/std/special/test_runner.zig:13:25: 0x225beb in ??? (test)
if (test_fn.func()) |_| {
^
root.main() catch |err| {
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:43:5: 0x2250e1 in ??? (test)
@noInlineCall(posixCallMainAndExit);
Tests failed. Use the following command to reproduce the failure:
/home/andy/dev/zig/docgen_tmp/test
At Compile-Time
test.zig
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:10:16: error: unreachable code
assert(@typeOf(unreachable) == noreturn);
^