E8003

E8003 — Compile-time index out of range

What the compiler reports

E8003 … index 5 is out of range: this array has 3 elements

The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.

A program that triggers it

//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// When both the array and the index are known during compilation, an index past the end
// is reported then and there rather than read at run time.
//

fn main() -> i32 {
  comptime {
    let a : Tensor<i64, [3]> = [ 3i64, 1i64, 2i64 ];
    let x = a[5];
  }
  return 0;
}

From tests/frontend/fail/comptime_array_index_out_of_range.vx, which asserts this diagnostic on every commit.

Related