]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Give consistent error message for invalid prefix in select component
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 20 Nov 2025 22:25:15 +0000 (23:25 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 9 Jan 2026 10:57:11 +0000 (11:57 +0100)
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.

gcc/ada/sem_ch4.adb
gcc/ada/sem_ch8.adb

index fa98d120a744af922323f9aa33b7390a75e0633f..1a9e37ce92da8b1bd11f6dde8a610ea025d060f9 100644 (file)
@@ -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;
 
index 8f534af7e1b4e405a9224feefbd9ae82306ab7f5..720e7f71662e5d82b0e9d54ee1a7d473475ab435 100644 (file)
@@ -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