diff mbox series

[Ada] Improve error message on missing all/for in quantified expression

Message ID 20211005082630.GA2693517@adacore.com
State New
Headers show
Series [Ada] Improve error message on missing all/for in quantified expression | expand

Commit Message

Pierre-Marie de Rodat Oct. 5, 2021, 8:26 a.m. UTC
When "for" or "some" keyword is missing from a quantified expression, it
is interpreted as an iterated component association by GNAT, leading to
misleading error messages such as:

badquant.ads:4:07: error: expected type "Standard.Boolean"
badquant.ads:4:07: error: found a composite type

Recognize this case specially to issue a better error message:

badquant.ads:4:11: error: missing "all" or "some" in quantified expression

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

gcc/ada/

	* sem_res.adb (Resolve): Recognize specially that case.
diff mbox series

Patch

diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -3098,6 +3098,24 @@  package body Sem_Res is
                      Error_Msg_N ("\use -gnatf for details", N);
                   end if;
 
+               --  Recognize the case of a quantified expression being mistaken
+               --  for an iterated component association because the user
+               --  forgot the "all" or "some" keyword after "for". Because the
+               --  error message starts with "missing ALL", we automatically
+               --  benefit from the associated CODEFIX, which requires that
+               --  the message is located on the identifier following "for"
+               --  in order for the CODEFIX to insert "all" in the right place.
+
+               elsif Nkind (N) = N_Aggregate
+                 and then List_Length (Component_Associations (N)) = 1
+                 and then Nkind (First (Component_Associations (N)))
+                   = N_Iterated_Component_Association
+                 and then Is_Boolean_Type (Typ)
+               then
+                  Error_Msg_N -- CODEFIX
+                    ("missing ALL or SOME in quantified expression",
+                     Defining_Identifier (First (Component_Associations (N))));
+
                else
                   Wrong_Type (N, Typ);
                end if;