--  At run time: a component passed to a procedure that propagates an exception: what the procedure changed
--  is the component's on the exceptional path too, as on the normal path (a limited record is
--  passed by reference), so the handler proves the exceptional case's fact about it.
with Ada.Text_IO;

procedure Main is
   Refused : exception;

   type Counter is limited record
      Value : Natural := 0;
   end record;

   type Holder is limited record
      Count : Counter;
      Tag : Character := 'a';
   end record;

   procedure Bump (C : in out Counter; Fail : Boolean)
     with Pre => C.Value < 100,
          Post => C.Value = C.Value'Old + 1,
          Exceptional_Cases => (Refused => Fail and then C.Value = C.Value'Old + 1)
   is
   begin
      C.Value := C.Value + 1;
      if Fail then
         raise Refused;
      end if;
   end Bump;

   H : Holder;
begin
   begin
      Bump (H.Count, True);
   exception
      when Refused =>
         Ada.Text_IO.Put_Line ("raised with" & Natural'Image (H.Count.Value));
   end;
   pragma Assert (H.Count.Value = 1 and then H.Tag = 'a');
end Main;
