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.

    1. $ zig test test.zig
    2. All tests passed.

    In fact, this is how assert is implemented:

    1. $ zig test test.zig
    2. 1/1 test "this will fail"...reached unreachable code
    3. /home/andy/dev/zig/docgen_tmp/test.zig:2:14: 0x2056db in assert (test)
    4. if (!ok) unreachable; // assertion failure
    5. ^
    6. assert(false);
    7. ^
    8. /home/andy/dev/zig/lib/std/special/test_runner.zig:13:25: 0x2283d1 in std.special.main (test)
    9. if (test_fn.func()) |_| {
    10. ^
    11. const result = root.main() catch |err| {
    12. ^
    13. /home/andy/dev/zig/lib/std/special/start.zig:102:5: 0x2270bf in std.special._start (test)
    14. @noInlineCall(posixCallMainAndExit);
    15. Tests failed. Use the following command to reproduce the failure:
    16. /home/andy/dev/zig/docgen_tmp/test

    At Compile-Time

    test.zig

    1. $ zig test test.zig
    2. /home/andy/dev/zig/docgen_tmp/test.zig:10:16: error: unreachable code
    3. assert(@typeOf(unreachable) == noreturn);
    4. ^