add error for accessing empty array

closes #134
This commit is contained in:
Andrew Kelley
2016-04-10 13:18:42 -07:00
parent 0683bd8bf6
commit b117b5907c
2 changed files with 10 additions and 0 deletions

View File

@@ -1814,6 +1814,13 @@ fn derp(){}
add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE(
const a: &u8 = null;
)SOURCE", 1, ".tmp_source.zig:2:16: error: expected maybe type, got '&u8'");
add_compile_fail_case("indexing an array of size zero", R"SOURCE(
const array = []u8{};
fn foo() {
const pointer = &array[0];
}
)SOURCE", 1, ".tmp_source.zig:4:27: error: out of bounds array access");
}
//////////////////////////////////////////////////////////////////////////////