diff mbox series

[Ada] Include generic instance names in non-visible entity errors

Message ID 20220111133244.GA749046@adacore.com
State New
Headers show
Series [Ada] Include generic instance names in non-visible entity errors | expand

Commit Message

Pierre-Marie de Rodat Jan. 11, 2022, 1:32 p.m. UTC
This patch adds the printing of generic instance names when encountering
non-visible entities instead of just the line number of the package
instantiation.

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

gcc/ada/

	* sem_ch8.adb (Nvis_Messages): Add generic instance name to
	error message.
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -5689,8 +5689,27 @@  package body Sem_Ch8 is
                      null;
 
                   else
-                     Error_Msg_N -- CODEFIX
-                       ("non-visible declaration#!", N);
+                     --  When the entity comes from a generic instance the
+                     --  normal error message machinery will give the line
+                     --  number of the generic package and the location of
+                     --  the generic instance, but not the name of the
+                     --  the instance.
+
+                     --  So, in order to give more descriptive error messages
+                     --  in this case, we include the name of the generic
+                     --  package.
+
+                     if Is_Generic_Instance (Scope (Ent)) then
+                        Error_Msg_Name_1 := Chars (Scope (Ent));
+                        Error_Msg_N -- CODEFIX
+                          ("non-visible declaration from %#!", N);
+
+                     --  Otherwise print the message normally
+
+                     else
+                        Error_Msg_N -- CODEFIX
+                          ("non-visible declaration#!", N);
+                     end if;
 
                      if Ekind (Scope (Ent)) /= E_Generic_Package then
                         Found := True;