diff mbox series

[Ada] Improve error message when function is used in a call statement

Message ID 20170906100930.GA54943@adacore.com
State New
Headers show
Series [Ada] Improve error message when function is used in a call statement | expand

Commit Message

Arnaud Charlet Sept. 6, 2017, 10:09 a.m. UTC
A typical error for new users of Ada is to call functions in a call
statement. Improve the error message for these users, to better indicate
what the error is in that case.

The following compilation raises the new message.

     $ gcc -c main.adb

     1. procedure Main is
     2.    function Lol return Integer is (0);
     3. begin
     4.    Lol;
           |
        >>> cannot use call to function "Lol" as a statement
        >>> return value of a function call cannot be ignored

     5. end Main;

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

2017-09-06  Yannick Moy  <moy@adacore.com>

	* sem_res.adb (Resolve): Update message for function call as statement.
diff mbox series

Patch

Index: sem_res.adb
===================================================================
--- sem_res.adb	(revision 251755)
+++ sem_res.adb	(working copy)
@@ -2533,8 +2533,11 @@ 
                  and then Ekind (Entity (Name (N))) = E_Function
                then
                   Error_Msg_NE
-                    ("cannot use function & in a procedure call",
+                    ("cannot use call to function & as a statement",
                      Name (N), Entity (Name (N)));
+                  Error_Msg_N
+                    ("\return value of a function call cannot be ignored",
+                     Name (N));
 
                --  Otherwise give general message (not clear what cases this
                --  covers, but no harm in providing for them).