E3044

E3044 — A top-level const whose value is not known while compiling, or does not fit its declared type. A const holds a number or a bool: a literal, or arithmetic on literals and other consts. A const table holds a list of number literals, and is read one number at a time, as TABLE[i].

What the compiler reports

Error[E3044] at [[@LINE+1]]:1: const 'CALLED' has no value known while compiling
Error[E3044] at [[@LINE+1]]:1: const 'ITSELF' has no value known while compiling
Error[E3044] at [[@LINE+1]]:1: const 'HALF' has a value whose type differs from the declared one

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 two() -> i32 {
  return 2;
}

// A function call has no value while compiling.
const CALLED : i32 = two();

// Defined through itself.
const ITSELF : i32 = ITSELF + 1;

// A float for an integer type.
const HALF : i32 = 1.5;

fn main() -> i32 {
  return CALLED + ITSELF + HALF;
}

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

Related