https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118082

            Bug ID: 118082
           Summary: Types from other packages are not visible inside
                    aggregate and reduction expressions inside generic
                    bodies
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liam at liampwll dot com
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

It appears that any types declared in other packages are not visible inside
aggregate and reduction expressions inside generic package bodies, but are
visible inside generic package specifications. This bug occurs on at least
13.3, 14.2, and mainline. This may be a duplicate of PR48039 but it is not
clear if this issue has the same cause.

Refer to the comments in the following code:

pragma Ada_2022;

procedure Tmp is
   package A is
      subtype T is Integer range 1..5;
   end A;

   package B is
      function F return Integer;
   end B;

   package body B is
      function F return Integer is
      begin
         if A.T'First < 3 then
            return [for X in A.T => X]'Reduce ("+", 0);
            --  No errors here, as expected.
         end if;
      end F;
   end B;

   generic package C is
      function F return Integer;
      function G return Integer is ([for X in A.T => X]'Reduce ("+", 0));
      --  No errors here, as expected.
   end C;

   package body C is
      function F return Integer is
      begin
         if A.T'First < 3 then
         --  A.T is visible above.
            return [for X in A.T => X]'Reduce ("+", 0);
            --  The above causes 'error: "A" is undefined'.
            --  The same error occurs if we define F as an expression function.
         end if;
      end F;
   end C;

   package D is new C;
   --  If the package is not instantiated then no error is reported.
begin
   null;
end Tmp;

Reply via email to