DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B4106: length check might fail

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

An array value is assigned to an object, or passed to a parameter, whose bounds are fixed, and the two might not have the same number of components. Ada slides the components into place (the first goes to the target's first index), but only when the lengths agree; when they differ the run-time check fails.

Example (Vada)

   Target : String (1 .. 8);
   ...
   Target := Source;   --  Source may not have 8 characters

Example (Varc)

    var target: String[1..=8];
    ...
    target = source;   // source may not have 8 characters

What to do (Vada)

Require the length in a precondition (Pre => Source'Length = 8), assign a slice of the right length (Target := Source (Source'First .. Source'First + 7);), or give the target its bounds from the value (Target : String := Source;).

What to do (Varc)

Require the length in a precondition (requires source::Length == 8), assign a slice of the right length (target = source[source::First..=source::First + 7];), or give the target its bounds from the value (var target: String = source;).

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.