-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
wrong branching of if(optional) in anonymous list literal #4491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
bug
Observed behavior contradicts documented or intended behavior
miscompilation
The compiler reports success but produces semantically incorrect code.
stage1
The process of building from source via WebAssembly and the C backend.
Milestone
Comments
More cases: test "wrong branching of if(runtime false) inside anonymous list literal" {
const T = i32;
var x: T = 0;
const a: T = 0;
const b: T = 1;
try testFmt(a, .{if (true) a else b});
try testFmt(b, .{if (false) a else b});
try testFmt(a, .{if (yes(true)) a else b});
try testFmt(b, .{if (no(false)) a else b}); // wrong
try testFmt(b, .{if (no(false)) unreachable else b});
//try testFmt(b, .{if (no(false)) a else unreachable}); // panic
try testFmt(a, .{if (x == a) a else unreachable});
try testFmt(b, .{if (x != a) unreachable else b});
try testFmt(b, .{if (x == b) unreachable else b});
try testFmt(a, .{if (x != b) a else unreachable});
try testFmt(a, .{if (x == a) a else b});
try testFmt(b, .{if (x != a) a else b}); // wrong
try testFmt(b, .{if (x == b) a else b}); // wrong
try testFmt(a, .{if (x != b) a else b});
try testFmt(a, .{switch (x) { b => unreachable, a => a, else => unreachable }});
try testFmt(a, .{switch (x) { b => b, a => a, else => unreachable }}); // wrong
try testFmt(a, .{switch (x) { b => unreachable, a => a, else => b }}); // wrong
try testFmt(a, .{switch (x) { a => a, b => unreachable, else => unreachable }});
try testFmt(a, .{switch (x) { a => a, b => unreachable, else => b }}); // wrong
try testFmt(a, .{switch (x) { a => a, b => b, else => unreachable }});
try testFmt(a, .{switch (x) { a => a, b => b, else => b }}); // wrong
}
fn yes(t: var) bool {
return true;
}
fn no(t: var) bool {
return false;
} |
const std = @import("std");
pub fn main() void {
var x = false;
std.debug.warn("{}\n", .{if (x) true else false}); // wrong
std.debug.warn("{}\n", .{if (!x) false else true}); // right
}
Is it always taking the first branch? |
just a small addition: putting "1>2" (resp. "1<2") instead of "x" (resp. "!x") in the if condition works correctly, i.e. prints "false" twice |
Duplicate of #3882 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Observed behavior contradicts documented or intended behavior
miscompilation
The compiler reports success but produces semantically incorrect code.
stage1
The process of building from source via WebAssembly and the C backend.
Uh oh!
There was an error while loading. Please reload this page.
version 5e37fc0 (master)
The text was updated successfully, but these errors were encountered: