u/Objective-Fox-9403

▲ 26 r/Zig

Inconsistency about unreachable code analysis

This code compiles:

test "can format empty document with template" {
    if (true) {
        return error.SkipZigTest;
    }

    // more code
}

While this one does not:

test "can format empty document with template" {
    return error.SkipZigTest;

    // more code
}

Zig complains about unreachable code in the second case, which is true. But I would have expected the same for the former.

Does this occur because Zig does not optimize if branches at all when testing?

reddit.com
u/Objective-Fox-9403 — 4 days ago