This adjusts the new Resolve_Implicit_Dereference procedure to the cases
where nodes in an instance do not have the proper view of a type that
was declared as private (a well-known limitation of the current
implementation of generic instantiations for types that are only
implicitly referenced in the generic code).

No functional changes.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-11  Eric Botcazou  <ebotca...@adacore.com>

gcc/ada/

        * sem_res.adb (Resolve_Implicit_Dereference): In an instance,
        reset the type of the prefix if it is private before building
        the dereference.
--- gcc/ada/sem_res.adb
+++ gcc/ada/sem_res.adb
@@ -8740,6 +8740,17 @@ package body Sem_Res is
       Desig_Typ : Entity_Id;
 
    begin
+      --  In an instance the proper view may not always be correct for
+      --  private types, see e.g. Sem_Type.Covers for similar handling.
+
+      if Is_Private_Type (Etype (P))
+        and then Present (Full_View (Etype (P)))
+        and then Is_Access_Type (Full_View (Etype (P)))
+        and then In_Instance
+      then
+         Set_Etype (P, Full_View (Etype (P)));
+      end if;
+
       if Is_Access_Type (Etype (P)) then
          Desig_Typ := Implicitly_Designated_Type (Etype (P));
          Insert_Explicit_Dereference (P);

Reply via email to