zig/test/cases/nested_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
437 B
Zig

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