]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious actual/formal matching check failure for formal derived type.
authorSteve Baird <baird@adacore.com>
Thu, 26 Jun 2025 19:23:53 +0000 (12:23 -0700)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 18 Jul 2025 08:29:50 +0000 (10:29 +0200)
In some cases involving a generic with two formal parameters, a formal package
and a formal derived type that is derived from an interface type declared in
the formal package, a legal instantiation of that generic is rejected with a
message incorrectly stating that the second actual parameter does not implement
the required interface.

gcc/ada/ChangeLog:

* sem_ch12.adb (Validate_Derived_Type_Instance): Cope with the case
where the ancestor type for a formal derived type is declared in
an earlier formal package but Get_Instance_Of does not return the
corresponding type from the corresponding actual package.

gcc/ada/sem_ch12.adb

index e80aea5fe762690f5d9133e344ddebcc6a4a51fe..1cb9d115cc586dad7952eaff763ee943d6d9271b 100644 (file)
@@ -14371,8 +14371,21 @@ package body Sem_Ch12 is
          elsif
            Scope (Scope (Base_Type (Etype (A_Gen_T)))) = Scope (A_Gen_T)
          then
-            Ancestor :=
-              Get_Instance_Of (Base_Type (Etype (A_Gen_T)));
+            declare
+               Formal_Ancestor : constant Entity_Id :=
+                 Base_Type (Etype (A_Gen_T));
+            begin
+               Ancestor := Get_Instance_Of (Formal_Ancestor);
+
+               --  Handle (rare) case where Get_Instance_Of found nothing in
+               --  the map.
+
+               if Ancestor = Formal_Ancestor then
+                  Ancestor :=
+                    Get_Instance_Of
+                      (Base_Type (Etype (Get_Instance_Of (A_Gen_T))));
+               end if;
+            end;
 
          --  The type may be a local derivation, or a type extension of a
          --  previous formal, or of a formal of a parent package.