[Ada] Better error message for "is null" subunit

Message ID 20191216103826.GA39390@adacore.com
State New
Headers show
Series
  • [Ada] Better error message for "is null" subunit
Related show

Commit Message

Pierre-Marie de Rodat Dec. 16, 2019, 10:38 a.m.
The syntax rules do not allow a null procedure as a subunit, and the
compiler was correctly rejecting that. This patch improves the error
message.

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

2019-12-16  Bob Duff  <duff@adacore.com>

gcc/ada/

	* sem_ch10.adb (Analyze_Subunit): Give an error if the subunit
	is not a proper body. This hides the confusing "duplicate body"
	message that was previously given.

Patch

--- gcc/ada/sem_ch10.adb
+++ gcc/ada/sem_ch10.adb
@@ -2433,6 +2433,20 @@  package body Sem_Ch10 is
 
       Install_Elaboration_Model (Par_Unit);
 
+      --  The syntax rules require a proper body for a subprogram subunit
+
+      if Nkind (Proper_Body (Sinfo.Unit (N))) = N_Subprogram_Declaration then
+         if Null_Present (Specification (Proper_Body (Sinfo.Unit (N)))) then
+            Error_Msg_N
+              ("null procedure not allowed as subunit",
+               Proper_Body (Unit (N)));
+         else
+            Error_Msg_N
+              ("subprogram declaration not allowed as subunit",
+               Defining_Unit_Name (Specification (Proper_Body (Unit (N)))));
+         end if;
+      end if;
+
       Analyze (Proper_Body (Unit (N)));
       Remove_Context (N);