From: Ronan Desplanques <desplanq...@adacore.com>

Some error processing paths in Enter_Name are adjusted so that error
messages are not affected.

gcc/ada/ChangeLog:

        * sem_ch3.adb (Process_Discriminants): Set Ekind earlier.
        * sem_util.adb (Enter_Name): Adjust error processing.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch3.adb  | 11 ++++++-----
 gcc/ada/sem_util.adb |  6 +++++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 968f9873805..77426929379 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -21246,6 +21246,12 @@ package body Sem_Ch3 is
 
       Discr := First (Discriminant_Specifications (N));
       while Present (Discr) loop
+         if Ekind (Defining_Identifier (Discr)) = E_In_Parameter then
+            Reinit_Field_To_Zero
+              (Defining_Identifier (Discr), F_Discriminal_Link);
+         end if;
+
+         Mutate_Ekind (Defining_Identifier (Discr), E_Discriminant);
          Enter_Name (Defining_Identifier (Discr));
 
          --  For navigation purposes we add a reference to the discriminant
@@ -21521,11 +21527,6 @@ package body Sem_Ch3 is
       while Present (Discr) loop
          Id := Defining_Identifier (Discr);
 
-         if Ekind (Id) = E_In_Parameter then
-            Reinit_Field_To_Zero (Id, F_Discriminal_Link);
-         end if;
-
-         Mutate_Ekind (Id, E_Discriminant);
          Set_Is_Not_Self_Hidden (Id);
          Reinit_Component_Location (Id);
          Reinit_Esize (Id);
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 3c80d236af8..faf49c33e16 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -8026,6 +8026,7 @@ package body Sem_Util is
             --  but the error should be posted on it, not on the component.
 
             elsif Ekind (E) = E_Discriminant
+              and then Is_Not_Self_Hidden (E)
               and then Present (Scope (Def_Id))
               and then Scope (Def_Id) /= Current_Scope
             then
@@ -8051,7 +8052,10 @@ package body Sem_Util is
                --  Avoid cascaded messages with duplicate components in
                --  derived types.
 
-               if Ekind (E) in E_Component | E_Discriminant then
+               if Ekind (E) = E_Component
+                 or else (Ekind (E) = E_Discriminant
+                          and then Is_Not_Self_Hidden (E))
+               then
                   return;
                end if;
             end if;
-- 
2.43.0

Reply via email to