]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Improve diagnostic when an incorrect left bracket is found
authorDenis Mazzucato <mazzucato@adacore.com>
Wed, 29 Oct 2025 16:43:29 +0000 (17:43 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 18 Nov 2025 15:05:10 +0000 (16:05 +0100)
This patch improves the generic error message of a missing binary operator when
an incorrect left bracket is found.

gcc/ada/ChangeLog:

* par-ch4.adb (P_Simple_Expression): Improve diagnostic.

gcc/ada/par-ch4.adb

index 338be465513ad6a3b358c9a154b1b607461fce1a..979fef06adc1e80b61b61c21ce8f08938531c646 100644 (file)
@@ -2783,15 +2783,23 @@ package body Ch4 is
       --  not the first token on a line (as determined by checking the
       --  previous token position with the start of the current line),
       --  then we insist that we have an appropriate terminating token.
-      --  Consider the following two examples:
+      --  Consider the following examples:
 
       --   1)  if A nad B then ...
 
-      --   2)  A := B
+      --   2)  if A [B] then ...
+      --            ^
+      --   2)  A := [B[;
+      --              ^
+
+      --   3)  A := B
       --       C := D
 
       --  In the first example, we would like to issue a binary operator
       --  expected message and resynchronize to the then. In the second
+      --  example, a left bracket was found instead of a left parenthesis (eg.
+      --  array indexing), or instead of a closing right bracket; in both cases
+      --  we issue an incorrect or mismatching bracket message. In the third
       --  example, we do not want to issue a binary operator message, so
       --  that instead we will get the missing semicolon message. This
       --  distinction is of course a heuristic which does not always work,
@@ -2827,6 +2835,11 @@ package body Ch4 is
                Error_Msg_SC ("\qualify expression to turn it into a name");
             end if;
 
+         --  Mistake of using brackets instead of parentheses
+
+         elsif Token = Tok_Left_Bracket then
+            Error_Msg_SC ("incorrect or mismatching bracket");
+
          --  Normal case for binary operator expected message
 
          else