[COMMITTED,16/51] ada: Improve error message for incorrect call arguments

Message ID 20260602084541.3829876-16-poulhies@adacore.com
State Committed
Commit a5e6571ead09734d89346d23b7f39cd5486959c6
Headers
Series [COMMITTED,01/51] ada: Rename Private_Component function |

Commit Message

Marc Poulhiès June 2, 2026, 8:45 a.m. UTC
  From: Viljar Indus <indus@adacore.com>

Enumeration literals are considered as zero argument functions.
This is not obvious for most users and can create confusing error
messages when an enumeration literal is referred to as a call. For
example if there are indices applied to it.

Instead create a dedicated error message for this scenario.

gcc/ada/ChangeLog:

	* sem_util.adb (Normalize_Actuals): Improve error message.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_util.adb | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 89060c31acd..1745accfe59 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -25981,7 +25981,19 @@  package body Sem_Util is
 
          if Reporting then
             if Is_Entity_Name (Name (N)) then
-               Error_Msg_N ("too many arguments in call to&", Name (N));
+               if Ekind (S) = E_Enumeration_Literal then
+                  Error_Msg_N ("cannot index enumeration literal &", Name (N));
+                  if Present (Homonym (S))
+                    and then Sloc (Homonym (S)) = Standard_Location
+                  then
+                     Error_Msg_NE
+                       ("\\did you mean & in Standard'?",
+                        Name (N),
+                        Homonym (S));
+                  end if;
+               else
+                  Error_Msg_N ("too many arguments in call to&", Name (N));
+               end if;
             else
                Error_Msg_N ("too many arguments in call", N);
             end if;