--  Slices as assignment targets and as `out` and `in out` actuals (D192, B7005-07, -09):
--  static and run-time bounds, an aggregate with the slice's bounds, a string's slice, a
--  record component's slice, and what the rest of the array keeps.
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   type Vector is array (1 .. 10) of Integer;
   type Row is array (Positive range <>) of Integer;
   type Line (N : Natural) is record
      Text : String (1 .. N);
   end record;

   procedure Fill (X : out Row; Value : Integer)
     with Post => (for all J in X'Range => X (J) = Value)
   is
   begin
      X := (others => Value);
   end Fill;

   procedure Bump (X : in out Row)
     with Pre => (for all J in X'Range => X (J) < 100),
          Post => (for all J in X'Range => X (J) = X'Old (J) + 1)
   is
      Before : constant Row := X;
   begin
      for K in X'Range loop
         X (K) := X (K) + 1;
         pragma Loop_Invariant (for all J in X'First .. K => X (J) = Before (J) + 1);
         pragma Loop_Invariant (for all J in X'Range => (if J > K then X (J) = Before (J)));
      end loop;
   end Bump;

   function Ident (X : Integer) return Integer is (X);

   V : Vector := (others => 0);
   R : Row (1 .. 8) := (others => 1);
   S : String (1 .. 5) := "hello";
   L : Line (6) := (N => 6, Text => "abcdef");
   M : constant Integer := Ident (4);
begin
   V (1 .. 2) := (5, 6);
   pragma Assert (V (1) = 5 and V (2) = 6 and V (3) = 0);
   V (3 .. 5) := (others => 7);
   pragma Assert (V (4) = 7 and V (6) = 0);
   if M in 2 .. 8 then
      R (2 .. M) := (others => 3);
      pragma Assert (R (1) = 1 and R (2) = 3 and R (M) = 3);
   end if;
   Fill (R (5 .. 6), 9);
   pragma Assert (R (5) = 9 and R (6) = 9 and R (7) = 1);
   Bump (R (7 .. 8));
   pragma Assert (R (7) = 2 and R (8) = 2);
   S (2 .. 3) := "EL";
   pragma Assert (S = "hELlo");
   L.Text (4 .. 6) := "XYZ";
   pragma Assert (L.Text (1) = 'a' and L.Text (5) = 'Y');
   V (6 .. 5) := (6 .. 5 => 1);
   Put_Line (Integer'Image (V (1)) & Integer'Image (V (4)) & Integer'Image (R (2)) & Integer'Image (R (5)) & Integer'Image (R (8)) & " " & S & " " & L.Text);
end Main;
