aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-07 15:11:20 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-07 15:11:20 -0700
commit26ea20d88fb1b201546e29058ac4aa5d4760a577 (patch)
tree9e6af6c20faa376f6ecfdd775950b8d29b4dea45 /test
parent049e9e581933921f2aaa1e60a8082c49fac236b2 (diff)
downloadzig-26ea20d88fb1b201546e29058ac4aa5d4760a577.tar.gz
zig-26ea20d88fb1b201546e29058ac4aa5d4760a577.zip
implement @const_eval
closes #73
Diffstat (limited to 'test')
-rw-r--r--test/run_tests.cpp7
-rw-r--r--test/self_hosted.zig7
2 files changed, 14 insertions, 0 deletions
diff --git a/test/run_tests.cpp b/test/run_tests.cpp
index 4d9de75bfa..318ba36f94 100644
--- a/test/run_tests.cpp
+++ b/test/run_tests.cpp
@@ -2020,6 +2020,13 @@ fn func() -> bogus {}
add_compile_fail_case("bogus compile var", R"SOURCE(
const x = @compile_var("bogus");
)SOURCE", 1, ".tmp_source.zig:2:24: error: unrecognized compile variable: 'bogus'");
+
+
+ add_compile_fail_case("@const_eval", R"SOURCE(
+fn a(x: i32) {
+ const y = @const_eval(x);
+}
+ )SOURCE", 1, ".tmp_source.zig:3:27: error: unable to evaluate constant expression");
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/test/self_hosted.zig b/test/self_hosted.zig
index 86beb173b0..2ea44adaaa 100644
--- a/test/self_hosted.zig
+++ b/test/self_hosted.zig
@@ -233,3 +233,10 @@ fn const_expr_eval_on_single_expr_blocks_fn(x: i32, b: bool) -> i32 {
return result;
}
+
+
+#attribute("test")
+fn builtin_const_eval() {
+ const x : i32 = @const_eval(1 + 2 + 3);
+ if (x != @const_eval(6)) unreachable{};
+}