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. Test 1/1 this will fail...reached unreachable code
    3. /home/andy/dev/zig/docgen_tmp/test.zig:2:14: 0x20424c in ??? (test)
    4. if (!ok) unreachable; // assertion failure
    5. ^
    6. assert(false);
    7. ^
    8. /home/andy/dev/zig/build/lib/zig/std/special/test_runner.zig:13:25: 0x225beb in ??? (test)
    9. if (test_fn.func()) |_| {
    10. ^
    11. root.main() catch |err| {
    12. ^
    13. /home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:43:5: 0x2250e1 in ??? (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. ^