add compile error for control flow using comptime var at runtime

closes #266
This commit is contained in:
Andrew Kelley
2017-02-24 13:57:00 -05:00
parent 4b99f5978f
commit 3b40aaa01f
3 changed files with 29 additions and 0 deletions

View File

@@ -1678,6 +1678,19 @@ fn assert(ok: bool) {
".tmp_source.zig:11:14: error: unable to evaluate constant expression",
".tmp_source.zig:7:20: note: called from here");
add_compile_fail_case("control flow uses comptime var at runtime", R"SOURCE(
fn foo() {
comptime var i = 0;
while (i < 5; i += 1) {
bar();
}
}
fn bar() { }
)SOURCE", 2,
".tmp_source.zig:4:5: error: control flow attempts to use compile-time variable at runtime",
".tmp_source.zig:4:21: note: compile-time variable assigned here");
}
//////////////////////////////////////////////////////////////////////////////