Patchwork [Ada] Rederivation of interface primitives

login
register
mail settings
Submitter Arnaud Charlet
Date June 21, 2010, 1:45 p.m.
Message ID <20100621134508.GA940@adacore.com>
Download mbox | patch
Permalink /patch/56320/
State New
Headers show

Comments

Arnaud Charlet - June 21, 2010, 1:45 p.m.
When a private extension  is completed by a full declaration, a visible
primitive operation of the parent type will be derived twice. The derivation
produced for the full type declaration must be ignored so that the one
associated with the visible partial view is available to clients. This patch
extends the corresponding check to the case where the parent type is an
interface type.

The following must compile quietly:

   gcc -c -gnat05 proxy.adb

---
with Pere, Fils;
package Proxy is

   type T_Proxy is new Pere.T_Pere with private;

   overriding function Action_Pere (This : in T_Proxy) return Boolean;

private
   type T_Proxy is new Pere.T_Pere with record
      Un_Fils : Fils.T_Fils_Class_Access;
   end record;
end Proxy;
---
package body Proxy is
   use Fils;

   function Action_Pere (This : in T_Proxy) return Boolean is
   begin
      return This.Un_Fils.Action_pere;
   end Action_Pere;
end Proxy;
---
with Pere;
package Fils is

   type T_Fils is abstract new Pere.T_Pere with private;

   type T_Fils_Class_Access is access all T_Fils'Class;

   function Action_Fils (This : in T_Fils) return Boolean;

private
     type T_Fils is abstract new Pere.T_Pere with null record;
end Fils;
---
package body Fils is
   function Action_Fils (This : in T_Fils) return Boolean is
   begin
      return T_Fils'Class (This).Action_Pere;
   end Action_Fils;
end Fils;
---
package Pere is
   type T_Pere is limited interface;

   function Action_Pere (This : in T_Pere) return Boolean is abstract;

end Pere;
---

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

2010-06-21  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch6.adb (New_Overloaded_Entity): If the new entity is a
	rederivation associated with a full declaration in a private part, and
	there is a partial view that derives the same parent subprogram, the
	new entity does not become visible. This check must be applied to
	interface operations as well.

Patch

Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb	(revision 161073)
+++ sem_ch6.adb	(working copy)
@@ -7526,9 +7526,11 @@  package body Sem_Ch6 is
       --  E exists and is overloadable
 
       else
-         --  Ada 2005 (AI-251): Derivation of abstract interface primitives
-         --  need no check against the homonym chain. They are directly added
-         --  to the list of primitive operations of Derived_Type.
+         --  Ada 2005 (AI-251): Derivation of abstract interface primitives.
+         --  They are directly added to the list of primitive operations of
+         --  Derived_Type, unless this is a rederivation in the private part
+         --  of an operation that was already derived in the visible part of
+         --  the current package.
 
          if Ada_Version >= Ada_05
            and then Present (Derived_Type)
@@ -7536,7 +7538,16 @@  package body Sem_Ch6 is
            and then Present (Find_Dispatching_Type (Alias (S)))
            and then Is_Interface (Find_Dispatching_Type (Alias (S)))
          then
-            goto Add_New_Entity;
+            if Type_Conformant (E, S)
+              and then Is_Package_Or_Generic_Package (Current_Scope)
+              and then In_Private_Part (Current_Scope)
+              and then Parent (E) /= Parent (S)
+              and then Alias (E) = Alias (S)
+            then
+               Check_Operation_From_Private_View (S, E);
+            else
+               goto Add_New_Entity;
+            end if;
          end if;
 
          Check_Synchronized_Overriding (S, Overridden_Subp);