--  General access types under ownership (G6): a library-level counter and a local one, each
--  taken by 'Access, then used only through its access value; proved and run.
with Ada.Text_IO;
procedure Main is
   type Counter is record
      Value : Integer := 0;
   end record;
   type Counter_Ref is access all Counter;

   Shared : aliased Counter;
   Ref : Counter_Ref := Shared'Access;

   procedure Bump (C : Counter_Ref) with Pre => C /= null and then C.Value < 100, Post => C.Value = C.Value'Old + 1 is
   begin
      C.Value := C.Value + 1;
   end Bump;

   procedure Local is
      type Local_Ref is access all Counter;
      Here : aliased Counter := (Value => 5);
      R : Local_Ref := Here'Access;
   begin
      R.Value := R.Value * 2;
      pragma Assert (R.Value = 10);
      Ada.Text_IO.Put_Line (Integer'Image (R.Value));
   end Local;
begin
   pragma Assert (Ref.Value = 0);
   Bump (Ref);
   Bump (Ref);
   pragma Assert (Ref.Value = 2);
   Ada.Text_IO.Put_Line (Integer'Image (Ref.Value));
   Local;
end Main;
