Patchwork [Ada] Visibility of equality operator when left operand is null.

login
register
mail settings
Submitter Arnaud Charlet
Date Dec. 5, 2012, 10:30 a.m.
Message ID <20121205103019.GA4582@adacore.com>
Download mbox | patch
Permalink /patch/203822/
State New
Headers show

Comments

Arnaud Charlet - Dec. 5, 2012, 10:30 a.m.
If the left operand of an equality operator is null, the visibility of the
operator must be determined from the interpretation of the right operand. This
processing was done for universal numeric types but not for Any_Access, the
internal representation of the type of the literal null.

Compiling my_procedure.adb must yield the error message:

   my_procedure.adb:7:12: operator for type "My_Access" defined at myproc_types.ads:3 is not directly visible
   my_procedure.adb:7:12: use clause would make operation legal

--
with Ada.Text_IO;
with MyProc_Types;

procedure My_Procedure is
   Local : MyProc_Types.My_Access;
begin
   if null /= Local then -- ERROR: use clause needed
      Ada.Text_IO.Put_Line ("Branch A");
   else
      Ada.Text_IO.Put_Line ("Branch B");
   end if;
end My_Procedure;
---
package MyProc_Types is
   type My_Record is limited private;
   type My_Access is access all My_Record;
private
   type My_Record is null record;
end MyProc_Types;

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

2012-12-05  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch4.adb (Find_Non_Universal_Interpretation): Use the
	types of the right operand if the left operand is null.

Patch

Index: sem_ch4.adb
===================================================================
--- sem_ch4.adb	(revision 194188)
+++ sem_ch4.adb	(working copy)
@@ -192,7 +192,9 @@ 
    --  of the operand types. If one of the operands has a universal interpre-
    --  tation,  the legality check uses some compatible non-universal
    --  interpretation of the other operand. N can be an operator node, or
-   --  a function call whose name is an operator designator.
+   --  a function call whose name is an operator designator. Any_Access, which
+   --  is the initial type of the literal NULL, is a universal type for the
+   --  purpose of this routine.
 
    function Find_Primitive_Operation (N : Node_Id) return Boolean;
    --  Find candidate interpretations for the name Obj.Proc when it appears
@@ -5504,6 +5506,7 @@ 
    begin
       if T1 = Universal_Integer
         or else T1 = Universal_Real
+        or else T1 = Any_Access
       then
          if not Is_Overloaded (R) then
             Add_One_Interp