zig/test/cases/blocks.zig
Alex Rønne Petersen 4dba253cd2
test: pull tests in test/cases/llvm/ up to test/cases/
There is nothing inherently LLVM-specific about any of these.
2025-09-16 23:39:29 +02:00

24 lines
396 B
Zig

fn assert(ok: bool) void {
if (!ok) unreachable;
}
fn foo(ok: bool) i32 {
const val: i32 = blk: {
var x: i32 = 1;
_ = &x;
if (!ok) break :blk x + 9;
break :blk x + 19;
};
return val + 10;
}
pub fn main() void {
assert(foo(false) == 20);
assert(foo(true) == 30);
}
// run
// backend=selfhosted,llvm
// target=x86_64-linux,x86_64-macos
//