https://gcc.gnu.org/g:e94fe9439a690912e79e4cdb9ba4a8287e0749f7

commit r16-2340-ge94fe9439a690912e79e4cdb9ba4a8287e0749f7
Author: Steve Baird <ba...@adacore.com>
Date:   Thu Jun 26 12:23:53 2025 -0700

    ada: Spurious actual/formal matching check failure for formal derived type.
    
    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.

Diff:
---
 gcc/ada/sem_ch12.adb | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index e80aea5fe762..1cb9d115cc58 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -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.

Reply via email to