diff mbox

[Ada] Additional information on subtype conformance error

Message ID 20121003080443.GA23275@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 3, 2012, 8:04 a.m. UTC
This patch adds a clarifying message info when subtype conformance fails, due
to a missing null exclusion indicatar in a formal that must  match a controlling
access formal. This Ada 2005 rule was checked partially in the context of
subprogram renamings but not for 'Access attribute references.

Compiling alpha.adb in gnat05 mode must be rejected with:

    alpha.adb:6:19: not subtype conformant with declaration at beta.ads:3
    alpha.adb:6:19: controlling formal "Ref" of "Updated" excludes null,
    declaration must exclude null as well

---
  with Beta;
  package Alpha is
     type Object is tagged limited null record;

     procedure Start;

     procedure Updated (Ref : access Object) is null;
  end Alpha;
---

  package body Alpha is

     procedure Start is
     begin
        Beta.Set (Updated'Access);
     end Start;
  end Alpha;
---
  limited with Alpha;
  package Beta is
     type Callback is access procedure (Ref : access Alpha.Object);

     procedure Set (Proc : in Callback) is null;
  end Beta;

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

2012-10-03  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch6.adb (Check_Conformance): Additional info when subtype
	conformance fails, due to a missing null exclusion indicatar in
	a formal that must match a controlling access formal.
diff mbox

Patch

Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb	(revision 192025)
+++ sem_ch6.adb	(working copy)
@@ -5756,14 +5756,31 @@ 
 
                declare
                   TSS_Name : constant TSS_Name_Type := Get_TSS_Name (New_Id);
+
                begin
                   if TSS_Name /= TSS_Stream_Read
                     and then TSS_Name /= TSS_Stream_Write
                     and then TSS_Name /= TSS_Stream_Input
                     and then TSS_Name /= TSS_Stream_Output
                   then
-                     Conformance_Error
-                       ("\type of & does not match!", New_Formal);
+                     --  Here we have a definite conformance error. It is worth
+                     --  special casesing the error message for the case of a
+                     --  controlling formal (which excludes null).
+
+                     if Is_Controlling_Formal (New_Formal) then
+                        Error_Msg_Node_2 := Scope (New_Formal);
+                        Conformance_Error
+                         ("\controlling formal& of& excludes null, "
+                           & "declaration must exclude null as well",
+                            New_Formal);
+
+                     --  Normal case (couldn't we give more detail here???)
+
+                     else
+                        Conformance_Error
+                          ("\type of & does not match!", New_Formal);
+                     end if;
+
                      return;
                   end if;
                end;