Is the syntax inconsistency intentional?

const print = @import("std").debug.print;

fn bar(n: i8) !usize {
    return if (n <= 0) error.A else 123;
}

pub fn main() !void {
    while (bar(0)) |_| { // The capture is optional.
        unreachable;
    } else |_| {
        print("while captures\n", .{});
    }

    while (bar(0)) { // compiles
        unreachable;
    } else |_| {
        print("while no capture\n", .{});
    }

    if (bar(0)) |_| { // The capture is required.
        unreachable;
    } else |_| {
        print("if captures\n", .{});
    }
    
    // Only this doesn't compile.
    if (bar(0)) {
        unreachable;
    } else |_| {
        print("if no capture\n", .{});
    }
}

I think this should not compile.

1 Like

It does compile now. So you think it is a bug?

Yes. I’m currently trying to fix it in the compiler.

5 Likes

#36757

3 Likes