Is this a compiler error?

Hello,

Could someone please try to compile/run the program below?

When I compile it, I get the following error:
—————————————————————————————–

test1.adb:16:04: error: instantiation error at a-coinve.ads:533
test1.adb:16:04: error: “Empty_Vector” conflicts with declaration at a-coinve.ads:533, instance at line 16 compilation of test1.adb failed
——————————————————————————————

When I remove the if construct, the compiler does not complain.

I use debian/alire 2.1.0

reinert

with Ada.Text_IO;
with Ada.Containers.Indefinite_Vectors;

procedure Test1 is
   use Ada.Containers;
   use Ada.Text_IO;

   function Is_Number1 (X : String) return Boolean is
      A : Float;
   begin
      A := Float'Value (X);
      return True;
   exception
      when others => return False;
   end Is_Number1;

   package Arg1_P is new Indefinite_Vectors (Positive, String);

   type Condition1_T is access function (X : String) return Boolean;

   function Find_Index1
     (X        : Arg1_P.Vector;
      Condition1 : Condition1_T;
      Forward1   : Boolean := True) return Integer
   is
   begin
      if Forward1 then
         for I in X.First_Index .. X.Last_Index loop
            return I when Condition1 (X (I));
         end loop;
      -- else
      --    for I in reverse X.First_Index .. X.Last_Index loop
      --       return I when Condition1 (X (I));
      --    end loop;
      end if;

      return Arg1_P.No_Index;
   end Find_Index1;

   A  : constant Arg1_P.Vector :=
     ["aa", "bbb", "23", "56.78", "hhh", "iiii"];

   I1 : constant Integer := Find_Index1 (A, Is_Number1'Access, Forward1 => True);
   I2 : constant Integer := Find_Index1 (A, Is_Number1'Access, Forward1 => False);

begin
   Put_Line ("a: " & A'Image);
   Put_Line ("i1, i2 : " & I1'Image & I2'Image);
end Test1;

Compiles and works OK with the native toolchain (Debian 12.2.0-14+deb12u1) (I removed GNAT extensions.)

Yes, for example this works for me also:

with Ada.Text_IO;
with ada.containers.indefinite_vectors;
procedure test1 is
   use ada.containers;
   use Ada.Text_IO;

   function is_number1(x : string) return boolean is
      a : float;
   begin
      a := float'Value(x);
      return true;
   exception
      when others => return false;
   end is_number1;

   package arg1_p is new indefinite_Vectors(Positive, String);
   type condition1_t is access function(x : String) return Boolean;

   function find_index1(x : arg1_p.Vector; condition1 : condition1_t; forward1 : boolean := true) return Integer is
     n : Integer := arg1_p.No_Index;
   begin
     if forward1 then
        for i in x.First_Index .. x.Last_Index when condition1(x(i)) loop
            n := i;
            Exit;
        end loop;
     else
        for i in reverse x.First_Index .. x.Last_Index when condition1(x(i)) loop
            n := i;
            Exit;
        end loop;
     end if;
     return n;
   end find_index1;

   a  : constant arg1_p.Vector := ["aa", "bbb", "23", "56.78", "hhh", "iiii"];
   i1 : constant Integer := find_index1(a,is_number1'Access,forward1 => true);
   i2 : constant Integer := find_index1(a,is_number1'Access,forward1 => false);
begin
   put_line("a: " & a'Image);
   put_line("i1,i2 : " & i1'Image & i2'Image);
end test1;