You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
conststd=@import("std");
pubfnmain() void {
varthe_answer: usize=42;
if (the_answer==0) {
std.debug.print("first: it's zero\n", .{});
} else|n| { // with capture, it is brokenstd.debug.print("first: {}\n", .{n});
}
if (the_answer==0) {
std.debug.print("second: it's zero\n", .{});
} else { // without capture, it is finestd.debug.print("second: {}\n", .{the_answer});
}
}
Expected Behavior
first: 42
second: 42
Actual Behavior
first: it's zero
second: 42
It does not make sense for an if on a boolean expression to allow a capture on the else.
And even worse than that it causes the true branch to be executed even if the expression is false 😰
The text was updated successfully, but these errors were encountered:
leecannon
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Jul 7, 2022
leecannon
changed the title
Else capture allowed for boolean condition and forces true branch
Else capture allowed for boolean condition and it forces true branch
Jul 7, 2022
Vexu
added
frontend
Tokenization, parsing, AstGen, Sema, and Liveness.
stage1
The process of building from source via WebAssembly and the C backend.
labels
Jul 7, 2022
Zig Version
0.10.0-dev.2860+c9006d947
Steps to Reproduce
Expected Behavior
Actual Behavior
It does not make sense for an if on a boolean expression to allow a capture on the else.
And even worse than that it causes the true branch to be executed even if the expression is false 😰
The text was updated successfully, but these errors were encountered: