* [Ada] Illegal declarations of deferred constants
@ 2014-10-23 10:20 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2014-10-23 10:20 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 863 bytes --]
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.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 990 bytes --]
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)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-10-23 10:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-23 10:20 [Ada] Illegal declarations of deferred constants Arnaud Charlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).