DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B1021: instance elaborated before its generic's body

Catalog status: active. Default severity: error. Stable name: instance-before-body. Family: Names and declarations.

An instance is elaborated where it is declared, and the body of its generic must have been elaborated by then. A generic declared in a package specification has its body in the package's body, so an instance in the same specification, or earlier in the body than the generic's body, would be elaborated too soon: Ada raises Program_Error there (RM 3.11(14)). Verada refuses such an instance when it is checked.

Example (Vada)

package Tables is
   generic
      Size : Positive;
   package Table is
      function Capacity return Positive;
   end Table;
   package Small is new Table (10);   --  Table's body is in Tables' body
end Tables;

What to do

Declare the instance after the generic's body: later in the package's body, or in a unit that names the package in a with clause (whose elaboration follows the package's body). A generic declared as a library unit of its own has no such order to keep.

Regression source and further reading

Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.

See names and declarations, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.