zig/test/cases3/null.zig

48 lines
716 B
Zig
Raw Normal View History

2016-12-22 06:20:08 +00:00
fn nullableType() {
@setFnTest(this);
const x : ?bool = true;
if (const y ?= x) {
if (y) {
// OK
} else {
@unreachable();
}
} else {
@unreachable();
}
const next_x : ?i32 = null;
const z = next_x ?? 1234;
assert(z == 1234);
const final_x : ?i32 = 13;
const num = final_x ?? @unreachable();
assert(num == 13);
}
2016-12-22 06:42:30 +00:00
fn assignToIfVarPtr() {
@setFnTest(this);
var maybe_bool: ?bool = true;
if (const *b ?= maybe_bool) {
*b = false;
}
assert(??maybe_bool == false);
}
2016-12-22 06:20:08 +00:00
// TODO const assert = @import("std").debug.assert;
fn assert(ok: bool) {
if (!ok)
@unreachable();
}