With This patch the compiler properly rejects a subprogram body whose
signature is type conformant with a previous expression function in
the same scope.

Compiling same_signature,adb must yield:

  same_signature.adb:8:04: body conflicts with expression function at line 5

---
with Ada.Text_IO; use Ada.Text_IO;

procedure Same_Signature is

   function My_Add (A, B : Integer) return Integer
   is (A - B);

   function My_Add (A, B : Integer) return Integer is
   begin
      return A + B;
   end My_Add;

begin
   Put_Line (My_Add (5, 6)'Img);
end Same_Signature;

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

2015-10-26  Ed Schonberg  <schonb...@adacore.com>

        * sem_ch6.adb (Find_Corresponding_Spec): Reject a subprogram
        body whose signature is type conformant with a previous expression
        function.

Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb (revision 229321)
+++ sem_ch6.adb (working copy)
@@ -7310,6 +7310,19 @@
                then
                   return E;
 
+               --  Expression functions can be completions, but cannot be
+               --  completed by an explicit body.
+
+               elsif Comes_From_Source (E)
+                 and then Comes_From_Source (N)
+                 and then Nkind (N) = N_Subprogram_Body
+                 and then Nkind (Original_Node (Unit_Declaration_Node (E))) =
+                            N_Expression_Function
+               then
+                  Error_Msg_Sloc := Sloc (E);
+                  Error_Msg_N ("body conflicts with expression function#", N);
+                  return Empty;
+
                elsif not Has_Completion (E) then
                   if Nkind (N) /= N_Subprogram_Body_Stub then
                      Set_Corresponding_Spec (N, E);

Reply via email to