aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-03-09 14:20:44 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-03-09 14:20:44 -0500
commit6db9be8900bf43632c8a98d91c6a92f30b33500a (patch)
treee5a9dde7f5cc3a44439e22c16695edac010b55ab /test
parentaaf2230ae89d74497042b7fada8c8023bf274dbd (diff)
downloadzig-6db9be8900bf43632c8a98d91c6a92f30b33500a.tar.gz
zig-6db9be8900bf43632c8a98d91c6a92f30b33500a.zip
don't memoize comptime functions if they can mutate state via parameters
closes #639
Diffstat (limited to 'test')
-rw-r--r--test/cases/eval.zig28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/cases/eval.zig b/test/cases/eval.zig
index e5e826effc..58877f7e25 100644
--- a/test/cases/eval.zig
+++ b/test/cases/eval.zig
@@ -420,3 +420,31 @@ test "binary math operator in partially inlined function" {
assert(s[2] == 0x90a0b0c);
assert(s[3] == 0xd0e0f10);
}
+
+
+test "comptime function with the same args is memoized" {
+ comptime {
+ assert(MakeType(i32) == MakeType(i32));
+ assert(MakeType(i32) != MakeType(f64));
+ }
+}
+
+fn MakeType(comptime T: type) type {
+ return struct {
+ field: T,
+ };
+}
+
+test "comptime function with mutable pointer is not memoized" {
+ comptime {
+ var x: i32 = 1;
+ const ptr = &x;
+ increment(ptr);
+ increment(ptr);
+ assert(x == 3);
+ }
+}
+
+fn increment(value: &i32) void {
+ *value += 1;
+}