Skip to content

TP0217

Error: const initializer is not a constant expression

  • const initializer must be a constant expression
  • class attribute value must be a constant expression (M28)

From the golden case tests/cases/m3/tp0217_const.tpn:

tp0217_const.tpn
const A = 2
const B = A * 2
const C = len("abc")
const D = 1 < 2
const E = f"x"
const F = (1 + 2) * -3 // 4 % 5 - 6.5 / 2
const G = "a" + "b"
const H = True

The compiler reports:

tp0217_const.tpn:2:11: error TP0217: const initializer must be a constant expression
tp0217_const.tpn:3:11: error TP0217: const initializer must be a constant expression
tp0217_const.tpn:4:11: error TP0217: const initializer must be a constant expression
tp0217_const.tpn:5:11: error TP0217: const initializer must be a constant expression

The specification lists every code.