diff mbox

[Ada] Illegal declarations of deferred constants

Message ID 20141023102015.GA21159@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 23, 2014, 10:20 a.m. UTC
A deferred constant whose type is an anonymous array is always illegal (unless
it is imported). This patch makes the error message more detailed, to help
future Ada beginners.

Compiling array_constant.ads  must yield:

   array_constant.ads:2:17: a deferred constant must have a named type
   array_constant.ads:4:04: type does not match declaration at line 2
   array_constant.ads:4:04: each anonymous array is a distinct type

---
package Array_Constant is
   A : constant array (Boolean) of Integer;
private
   A : constant array (Boolean) of Integer := (
     True => 1, False => 0
   );
end Array_Constant;

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

2014-10-23  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb (Constant_Redeclaration): Make error message more
	explicit on a deferred constant whose object_definition is an
	anonymous array.
diff mbox

Patch

Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb	(revision 216583)
+++ sem_ch3.adb	(working copy)
@@ -11751,6 +11751,20 @@ 
          Set_Full_View (Prev, Id);
          Set_Etype (Id, Any_Type);
 
+         --  A deferred constant whose type is an anonymous array is always
+         --  illegal (unless imported). A detailed error message might be
+         --  helpful for Ada beginners.
+
+         if Nkind (Object_Definition (Parent (Prev)))
+            = N_Constrained_Array_Definition
+           and then Nkind (Object_Definition (N))
+              = N_Constrained_Array_Definition
+         then
+            Error_Msg_N ("\each anonymous array is a distinct type", N);
+            Error_Msg_N ("a deferred constant must have a named type",
+              Object_Definition (Parent (Prev)));
+         end if;
+
       elsif
         Null_Exclusion_Present (Parent (Prev))
           and then not Null_Exclusion_Present (N)