| author | |
| committer | |
| log | b117b5907c50f495c53770bfc351e0431e6474b3 |
| tree | 38565c201e7dd562fc10db66f9f15b56d424a2d1 |
| parent | 0683bd8bf66c00d38f79d49319b5d80ac1f9a470 |
closes #1342 files changed, 10 insertions(+), 0 deletions(-)
src/analyze.cpp+3| ... | ... | @@ -2445,6 +2445,9 @@ static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *i |
| 2445 | 2445 | if (array_type->id == TypeTableEntryIdInvalid) { |
| 2446 | 2446 | return_type = g->builtin_types.entry_invalid; |
| 2447 | 2447 | } else if (array_type->id == TypeTableEntryIdArray) { |
| 2448 | if (array_type->data.array.len == 0) { | |
| 2449 | add_node_error(g, node, buf_sprintf("out of bounds array access")); | |
| 2450 | } | |
| 2448 | 2451 | return_type = array_type->data.array.child_type; |
| 2449 | 2452 | } else if (array_type->id == TypeTableEntryIdPointer) { |
| 2450 | 2453 | return_type = array_type->data.pointer.child_type; |
test/run_tests.cpp+7| ... | ... | @@ -1814,6 +1814,13 @@ fn derp(){} |
| 1814 | 1814 | add_compile_fail_case("assign null to non-nullable pointer", R"SOURCE( |
| 1815 | 1815 | const a: &u8 = null; |
| 1816 | 1816 | )SOURCE", 1, ".tmp_source.zig:2:16: error: expected maybe type, got '&u8'"); |
| 1817 | ||
| 1818 | add_compile_fail_case("indexing an array of size zero", R"SOURCE( | |
| 1819 | const array = []u8{}; | |
| 1820 | fn foo() { | |
| 1821 | const pointer = &array[0]; | |
| 1822 | } | |
| 1823 | )SOURCE", 1, ".tmp_source.zig:4:27: error: out of bounds array access"); | |
| 1817 | 1824 | } |
| 1818 | 1825 | |
| 1819 | 1826 | ////////////////////////////////////////////////////////////////////////////// |