E4010

E4010 — A change to a variable declared without mut: assigning it, or a field or element of it, borrowing it &mut, or calling a method that takes &mut self on it. Declare it let mut x, or for a parameter mut x : T.

What the compiler reports

Error[E4010] at [[@LINE+1]]:{{[0-9]+}}: `GOOD` is a `const`, so it cannot be assigned
Error[E3044] at [[@LINE+1]]:11: const 'GOOD' is a table: read it one number at a time, as `GOOD[i]`

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
//

fn one() -> i8 {
  return 1i8;
}

const SHORT : Tensor<i8, [3]> = [1, 2];

const CALLED : Tensor<i8, [2]> = [1, one()];

const TOO_BIG : Tensor<i8, [2]> = [1, 300];

const FLAGS : Tensor<bool, [1]> = [true];

const GOOD : Tensor<i8, [2]> = [1, 2];

fn main() -> i32 {
  let a = SHORT[0] + CALLED[0] + TOO_BIG[0];
  let b = FLAGS[0];
  // A table is read-only.
  GOOD[0] = 5i8;
  // A table is read one number at a time, never bound or passed whole.
  let c = GOOD;
  return 0;
}

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

Related