From: Denis Mazzucato Date: Wed, 29 Oct 2025 16:43:29 +0000 (+0100) Subject: ada: Improve diagnostic when an incorrect left bracket is found X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f5802e35840034f7b0d2ebf4901742983792046;p=thirdparty%2Fgcc.git ada: Improve diagnostic when an incorrect left bracket is found 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. --- diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb index 338be465513..979fef06adc 100644 --- a/gcc/ada/par-ch4.adb +++ b/gcc/ada/par-ch4.adb @@ -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