aboutsummaryrefslogtreecommitdiff
path: root/test/self_hosted2.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-12-05 19:12:19 -0500
committerAndrew Kelley <superjoe30@gmail.com>2016-12-05 19:12:19 -0500
commitbed83bc5a14aa6c0480dcfa842d97cce64427e1b (patch)
tree2bb49ff047be1ecc39683c208240845f80ca5e27 /test/self_hosted2.zig
parent24048b2af62f1b36678aa08a20d0754cb712e485 (diff)
downloadzig-bed83bc5a14aa6c0480dcfa842d97cce64427e1b.tar.gz
zig-bed83bc5a14aa6c0480dcfa842d97cce64427e1b.zip
IR: implement short circuit bool or, and
Diffstat (limited to 'test/self_hosted2.zig')
-rw-r--r--test/self_hosted2.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/self_hosted2.zig b/test/self_hosted2.zig
index 891c1c168a..34daba6937 100644
--- a/test/self_hosted2.zig
+++ b/test/self_hosted2.zig
@@ -152,6 +152,33 @@ fn testContinueInForLoop() {
assert(sum == 6);
}
+fn shortCircuit() {
+ var hit_1 = false;
+ var hit_2 = false;
+ var hit_3 = false;
+ var hit_4 = false;
+
+ if (true || {assert(false); false}) {
+ hit_1 = true;
+ }
+ if (false || { hit_2 = true; false }) {
+ assert(false);
+ }
+
+ if (true && { hit_3 = true; false }) {
+ assert(false);
+ }
+ if (false && {assert(false); false}) {
+ assert(false);
+ } else {
+ hit_4 = true;
+ }
+ assert(hit_1);
+ assert(hit_2);
+ assert(hit_3);
+ assert(hit_4);
+}
+
fn assert(ok: bool) {
if (!ok)
@@ -173,6 +200,7 @@ fn runAllTests() {
testCompileTimeGenericEval();
testFnWithInlineArgs();
testContinueInForLoop();
+ shortCircuit();
}
export nakedcc fn _start() -> unreachable {