diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-05 19:12:19 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-05 19:12:19 -0500 |
| commit | bed83bc5a14aa6c0480dcfa842d97cce64427e1b (patch) | |
| tree | 2bb49ff047be1ecc39683c208240845f80ca5e27 /test | |
| parent | 24048b2af62f1b36678aa08a20d0754cb712e485 (diff) | |
| download | zig-bed83bc5a14aa6c0480dcfa842d97cce64427e1b.tar.gz zig-bed83bc5a14aa6c0480dcfa842d97cce64427e1b.zip | |
IR: implement short circuit bool or, and
Diffstat (limited to 'test')
| -rw-r--r-- | test/self_hosted2.zig | 28 |
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 { |
