with Ada.Text_IO; use Ada.Text_IO;
--  A record with a part held apart passed by reference (D191): an exception after the
--  procedure wrote its part leaves the caller's object as the procedure left it, which proof
--  allows (after an exception it assumes nothing of the object but its type's facts).
procedure Main is
   subtype Len is Natural range 0 .. 1_000_000;
   type Buf (N : Len := 0) is record
      Data : String (1 .. N);
   end record;
   Stop : exception;
   procedure Touch (B : in out Buf; Fail : Boolean)
     with Pre => B.N >= 1,
          Post => B.Data (1) = 'w',
          Exceptional_Cases => (Stop => Fail)
   is
   begin
      B.Data (1) := 'w';
      if Fail then
         raise Stop;
      end if;
   end Touch;
   X : Buf (200_000);
begin
   X.Data := (others => 'a');
   begin
      Touch (X, True);
   exception
      when Stop =>
         if X.N >= 2 then
            Put_Line (X.Data (1 .. 2));
         end if;
   end;
end Main;
