DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B2016: Type_Invariant on both views of a private type

Catalog status: active. Default severity: error. Stable name: partial-view-invariant. Family: Types and constraints.

A private type's invariant may be given where the private type is declared or on its full declaration in the private part (Ada RM 7.3.2(2/3)). Either way it is the full view's invariant: it is about the representation, and it is checked where values leave the package. A type has one invariant, so it may not be given on both views.

Example (Vada)

   type Stack is private
     with Type_Invariant => Valid (Stack);
   ...
private
   type Stack is record
      ...
   end record
     with Type_Invariant => Stack.Top <= Max;

What to do

Give the invariant once, on either view, joining the conditions with and then.

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.