On this page
B4102: range check might fail
Catalog status: active. Default severity: error. Stable name: range-check. Family: Executable checks.
A value is stored into an object, parameter or result whose subtype is narrower than the value's type, and the prover could not show that the value is always within the subtype's range. At run time this raises Constraint_Error. The secondary label shows where the subtype is declared.
Example (Vada)
function Previous (N : Natural) return Natural is
begin
return N - 1; -- -1 when N = 0
end Previous;Example (Varc)
pub fn previous(n: Natural) -> Natural {
return n - 1; // -1 when n == 0
}
What to do (Vada)
Add a precondition that excludes the failing values (with Pre => N > 0), handle them separately, or widen the target's subtype.
What to do (Varc)
Add a precondition that excludes the failing values (requires n > 0), handle them separately, or widen the target's subtype.
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See executable checks, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.