aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/eval.zig
diff options
context:
space:
mode:
authorMartin Wickham <spexguy070@gmail.com>2021-09-28 12:00:35 -0500
committerGitHub <noreply@github.com>2021-09-28 12:00:35 -0500
commit1cc5d4e758a95be373756e7c32f9bb46d21633c9 (patch)
tree9c142d3d009e1622f27a22c9228a6ff10b878721 /test/behavior/eval.zig
parent60b6e74468570a124f602a62b6bd2da95ba8c17c (diff)
downloadzig-1cc5d4e758a95be373756e7c32f9bb46d21633c9.tar.gz
zig-1cc5d4e758a95be373756e7c32f9bb46d21633c9.zip
Stage 2: Support inst.func() syntax (#9827)
* Merge call zir instructions to make space for field_call * Fix bug with comptime known anytype args * Delete the param_type zir instruction * Move some passing tests to stage 2 * Implement a.b() function calls * Add field_call_bind support for call and field builtins
Diffstat (limited to 'test/behavior/eval.zig')
-rw-r--r--test/behavior/eval.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig
index 0d103bc49a..6acdf15e89 100644
--- a/test/behavior/eval.zig
+++ b/test/behavior/eval.zig
@@ -155,3 +155,31 @@ fn MakeType(comptime T: type) type {
field: T,
};
}
+
+test "try to trick eval with runtime if" {
+ try expect(testTryToTrickEvalWithRuntimeIf(true) == 10);
+}
+
+fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
+ comptime var i: usize = 0;
+ inline while (i < 10) : (i += 1) {
+ const result = if (b) false else true;
+ _ = result;
+ }
+ comptime {
+ return i;
+ }
+}
+
+test "@setEvalBranchQuota" {
+ comptime {
+ // 1001 for the loop and then 1 more for the expect fn call
+ @setEvalBranchQuota(1002);
+ var i = 0;
+ var sum = 0;
+ while (i < 1001) : (i += 1) {
+ sum += i;
+ }
+ try expect(sum == 500500);
+ }
+}