https://gcc.gnu.org/g:4b2e181b1f87ea186ca5d382b12a0fed53c94c64

commit r16-6597-g4b2e181b1f87ea186ca5d382b12a0fed53c94c64
Author: Eric Botcazou <[email protected]>
Date:   Thu Nov 20 23:25:15 2025 +0100

    ada: Give consistent error message for invalid prefix in select component
    
    This gives a consistent error message for an invalid prefix in all the cases
    where the prefix has been found to be the name of an entity.
    
    gcc/ada/ChangeLog:
    
            * sem_ch4.adb (Analyze_Selected_Component): Give a specific error
            message for an invalid prefix that is the dereference of a name.
            * sem_ch8.adb (Find_Selected_Component): Give a consistent error
            message for the name of an invalid prefix.

Diff:
---
 gcc/ada/sem_ch4.adb | 17 +++++++++++++++--
 gcc/ada/sem_ch8.adb |  7 +++----
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
index fa98d120a744..1a9e37ce92da 100644
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -6152,9 +6152,22 @@ package body Sem_Ch4 is
       then
          return;
 
-      else
-         --  Invalid prefix
+      --  Invalid prefix. If it is the dereference of a name, we give the same
+      --  error message as would be given if the dereference was implicit.
+
+      elsif Nkind (Pref) = N_Explicit_Dereference
+        and then Is_Entity_Name (Prefix (Pref))
+      then
+         Error_Msg_N
+           ("invalid prefix& in selected component", Prefix (Pref));
 
+         if Is_Incomplete_Type (Etype (Pref)) then
+            Error_Msg_N
+              ("\dereference must not be of an incomplete type "
+               & "(RM 3.10.1)", Prefix (Pref));
+         end if;
+
+      else
          Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
       end if;
 
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 8f534af7e1b4..720e7f71662e 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -8585,8 +8585,7 @@ package body Sem_Ch8 is
                   if Ekind (P_Name) /= E_Function
                     and then not Is_Overloaded (P)
                   then
-                     Error_Msg_NE
-                       ("invalid prefix& in selected component", N, P_Name);
+                     Error_Msg_N ("invalid prefix& in selected component", P);
                      Diagnose_Call;
                      return;
 
@@ -8711,7 +8710,7 @@ package body Sem_Ch8 is
                   end if;
                end;
 
-               Error_Msg_N ("invalid prefix in selected component&", P);
+               Error_Msg_N ("invalid prefix& in selected component", P);
 
                if Is_Incomplete_Type (P_Type)
                  and then Is_Access_Type (Etype (P))
@@ -8722,7 +8721,7 @@ package body Sem_Ch8 is
                end if;
 
             else
-               Error_Msg_N ("invalid prefix in selected component", P);
+               Error_Msg_N ("invalid prefix& in selected component", P);
             end if;
          end if;
       else

Reply via email to