B2002: static expression is out of range or undefined
Catalog status: active. Default severity: error. Stable name: static-value-out-of-range. Family: Types and constraints.
A static expression is evaluated at compile time. Its value must fit in the base range of its type (Ada RM 4.9), and it must be defined: no division by zero, no negative exponent of an integer, and integer types no larger than 128 bits.
A numeric literal is refused where it is read when no numeric type holds its value: a real literal beyond Long_Float'Last or so small that Long_Float would round it to 0, or an integer literal of 2 ** 66 bits or more (no memory holds it). A universal integer has no other limit: N : constant := 10 ** 5000 / 10 ** 4998; is 100. An integer literal of more than 65,536 bits is kept unexpanded until it is used: where a typed value is expected (every integer type holds at most 128 bits) it is refused without being expanded, so X : Integer := 1E999999999; costs nothing to refuse.
Example (Vada)
type Byte is mod 256;
B : Byte := 300;
X : constant := 10 / 0;
Y : constant := 1.0E999999999;Example (Varc)
type Byte = mod 256;
var b: Byte = 300;
let x = 10 / 0;
let y = 1.0e999999999;
What to do
Fix the value or the type's range.
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See types and constraints, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.