]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Interfaces order disables class-wide prefix notation calls
authorJavier Miranda <miranda@adacore.com>
Fri, 26 Apr 2024 18:22:19 +0000 (18:22 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 13 Jun 2024 13:30:31 +0000 (15:30 +0200)
When the first formal parameter of a subprogram is a class-wide
interface type (or an access to a class-wide interface type),
changing the order of the interface types implemented by a
type declaration T enables or disables the ability to use the
prefix notation to call it with objects of type T. When the
call is disabled the compiler rejects it reporting an error.

gcc/ada/

* sem_ch4.adb (Traverse_Interfaces): Add missing support
for climbing to parents of interface types.

gcc/ada/sem_ch4.adb

index 03364dade9f63c76c126531e415ec4f41198beb8..b59a56c139b9207208f224fca21f9d75233c57b5 100644 (file)
@@ -9805,11 +9805,23 @@ package body Sem_Ch4 is
          begin
             Error := False;
 
+            --  When climbing through the parents of an interface type,
+            --  look for acceptable class-wide homonyms associated with
+            --  the interface type.
+
+            if Is_Interface (Anc_Type) then
+               Traverse_Homonyms (Anc_Type, Error);
+
+               if Error then
+                  return;
+               end if;
+            end if;
+
             Intface := First (Intface_List);
             while Present (Intface) loop
 
                --  Look for acceptable class-wide homonyms associated with the
-               --  interface.
+               --  interface type.
 
                Traverse_Homonyms (Etype (Intface), Error);
 
@@ -9828,6 +9840,15 @@ package body Sem_Ch4 is
 
                Next (Intface);
             end loop;
+
+            --  For derived interface types continue the search climbing to
+            --  the parent type.
+
+            if Is_Interface (Anc_Type)
+              and then Etype (Anc_Type) /= Anc_Type
+            then
+               Traverse_Interfaces (Etype (Anc_Type), Error);
+            end if;
          end Traverse_Interfaces;
 
       --  Start of processing for Try_Class_Wide_Operation