add error for dividing by zero in static function evaluation

This commit is contained in:
Andrew Kelley
2016-04-12 16:18:41 -07:00
parent be4df96e4b
commit 69109bc270
6 changed files with 65 additions and 58 deletions

View File

@@ -1481,6 +1481,16 @@ fn foo() {
const pointer = &array[0];
}
)SOURCE", 1, ".tmp_source.zig:4:27: error: out of bounds array access");
add_compile_fail_case("compile time division by zero", R"SOURCE(
const x = foo(0);
fn foo(x: i32) -> i32 {
1 / x
}
)SOURCE", 3,
".tmp_source.zig:3:1: error: function evaluation caused division by zero",
".tmp_source.zig:2:14: note: called from here",
".tmp_source.zig:4:7: note: division by zero here");
}
//////////////////////////////////////////////////////////////////////////////