From bed83bc5a14aa6c0480dcfa842d97cce64427e1b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 5 Dec 2016 19:12:19 -0500 Subject: IR: implement short circuit bool or, and --- test/self_hosted2.zig | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') 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 { -- cgit v1.2.3