DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B4103: index check might fail

Catalog status: active. Default severity: error. Stable name: index-check. Family: Executable checks.

An array is indexed with a value that might lie outside the array's index range.

Example (Vada)

   type Table is array (1 .. 10) of Integer;
   function Square (N : Integer) return Integer is (Squares (N));   --  N = 11 is outside

Example (Varc)

    type Table = [1..=10]Integer;
    fn square(n: Integer) -> Integer = squares[n];   // n == 11 is outside

What to do (Vada)

Give the index the array's index subtype (N : Table_Index), add a precondition (with Pre => N in Squares'Range), or test the index before using it.

What to do (Varc)

Give the index the array's index subtype (n: Table_Index), add a precondition (requires n in squares::Range), or test the index before using it.

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.