mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
451ce09067
* `noreturn` is the primitive type. * `unreachable` is a control flow keyword. * `@unreachable()` builtin function is deleted. closes #214
38 lines
570 B
Zig
38 lines
570 B
Zig
const assert = @import("std").debug.assert;
|
|
|
|
test "gotoAndLabels" {
|
|
gotoLoop();
|
|
assert(goto_counter == 10);
|
|
}
|
|
fn gotoLoop() {
|
|
var i: i32 = 0;
|
|
goto cond;
|
|
loop:
|
|
i += 1;
|
|
cond:
|
|
if (!(i < 10)) goto end;
|
|
goto_counter += 1;
|
|
goto loop;
|
|
end:
|
|
}
|
|
var goto_counter: i32 = 0;
|
|
|
|
|
|
|
|
test "gotoLeaveDeferScope" {
|
|
testGotoLeaveDeferScope(true);
|
|
}
|
|
fn testGotoLeaveDeferScope(b: bool) {
|
|
var it_worked = false;
|
|
|
|
goto entry;
|
|
exit:
|
|
if (it_worked) {
|
|
return;
|
|
}
|
|
unreachable;
|
|
entry:
|
|
defer it_worked = true;
|
|
if (b) goto exit;
|
|
}
|