This patch adds the name of entity that is improperly used as the name in a
package or subprogram instantiation.

Compiling generic_test.adb must yield:

    generic_test.adb:30:10: "E" is not the name of a generic package

---
procedure Generic_Test is

   generic
      M : Positive;
   package G is
      type S is private;
   private
      type S is new Integer;
   end G;

   generic
      with package B is
        new G (<>);
   function E
     (L : B.S) return Boolean;

   function E
     (L : B.S) return Boolean is
   begin

      return True;

   end E;

   package B_6 is
     new G (6);

   -- function B_6_E is
   package B_6_E is -- Gives "expect name of generic package in instantiation"
     new E (B_6);

begin
   null;
end Generic_Test;

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

2013-10-10  Ed Schonberg  <schonb...@adacore.com>

        * sem_ch12.adb (Analyze_Package_Instantiation,
        Analyze_Subprogram_Instantiation): Improve error message when
        name in instantiation does not designate a generic unit of the
        right kind.

Index: sem_ch12.adb
===================================================================
--- sem_ch12.adb        (revision 203342)
+++ sem_ch12.adb        (working copy)
@@ -3479,8 +3479,8 @@
             Error_Msg_N
               ("cannot instantiate a limited withed package", Gen_Id);
          else
-            Error_Msg_N
-              ("expect name of generic package in instantiation", Gen_Id);
+            Error_Msg_NE
+              ("& is not the name of a generic package", Gen_Id, Gen_Unit);
          end if;
 
          Restore_Env;
@@ -4669,34 +4669,17 @@
       --  Verify that it is a generic subprogram of the right kind, and that
       --  it does not lead to a circular instantiation.
 
-      if not Ekind_In (Gen_Unit, E_Generic_Procedure, E_Generic_Function) then
-         Error_Msg_N ("expect generic subprogram in instantiation", Gen_Id);
+      if K = E_Procedure and then Ekind (Gen_Unit) /= E_Generic_Procedure then
+         Error_Msg_NE
+           ("& is not the name of a generic procedure", Gen_Id, Gen_Unit);
 
+      elsif K = E_Function and then Ekind (Gen_Unit) /= E_Generic_Function then
+         Error_Msg_NE
+           ("& is not the name of a generic function", Gen_Id, Gen_Unit);
+
       elsif In_Open_Scopes (Gen_Unit) then
          Error_Msg_NE ("instantiation of & within itself", N, Gen_Unit);
 
-      elsif K = E_Procedure
-        and then Ekind (Gen_Unit) /= E_Generic_Procedure
-      then
-         if Ekind (Gen_Unit) = E_Generic_Function then
-            Error_Msg_N
-              ("cannot instantiate generic function as procedure", Gen_Id);
-         else
-            Error_Msg_N
-              ("expect name of generic procedure in instantiation", Gen_Id);
-         end if;
-
-      elsif K = E_Function
-        and then Ekind (Gen_Unit) /= E_Generic_Function
-      then
-         if Ekind (Gen_Unit) = E_Generic_Procedure then
-            Error_Msg_N
-              ("cannot instantiate generic procedure as function", Gen_Id);
-         else
-            Error_Msg_N
-              ("expect name of generic function in instantiation", Gen_Id);
-         end if;
-
       else
          Set_Entity (Gen_Id, Gen_Unit);
          Set_Is_Instantiated (Gen_Unit);

Reply via email to