From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.13.192.193 with SMTP id b184mr7522985ywd.144.1495301606488; Sat, 20 May 2017 10:33:26 -0700 (PDT) X-Received: by 10.157.40.242 with SMTP id s105mr322306ota.5.1495301606447; Sat, 20 May 2017 10:33:26 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!t26no596483qtg.1!news-out.google.com!m134ni4033itb.0!nntp.google.com!67no966889itx.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 20 May 2017 10:33:26 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.201.205; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.201.205 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Preventing private procedure visibility being made public through extension From: Jere Injection-Date: Sat, 20 May 2017 17:33:26 +0000 Content-Type: text/plain; charset="UTF-8" Xref: news.eternal-september.org comp.lang.ada:46823 Date: 2017-05-20T10:33:26-07:00 List-Id: I tried to whittle this down to a small example, so forgive the uselessness of the example itself. I'm extending a library with some of my own components and I want (if possible) to allow my components to interact with the other library components as seamlessly as possible. Say a library provides a tagged type with the following procedure: Base.ads ************************************************* package Base is type Base_Param is tagged null record; type Base_Type is tagged null record; procedure Something (Obj : in out Base_Type; Value : Base_Param'Class) is null; end Base; ************************************************* keep in mind declaring the procedure as "is null" is just for example sake. In real life it would have a body. I want to extend both of the types in that package to do some extra processing. In particular, I want to override the procedure Something so that it does more than the version for Base_Type and so it takes in my derived param class as a parameter. I also want to prevent a client from calling the inherited version of the procedure Something as it would bypass the code I have in my new prototype of the procedure. I declare the package like this: Derived.ads ************************************************* with Base; package Derived is type Derived_Param is new Base.Base_Param with null record; type Derived_Type is new Base.Base_Type with private; procedure Something (Obj : in out Derived_Type; Value : Derived_Param'Class) is null; type More_Derived_Type is new Derived_Type with private; private type Derived_Type is new Base.Base_Type with null record; overriding procedure Something (Obj : in out Derived_Type; Value : Base.Base_Param'Class) is null; type More_Derived_Type is new Derived_Type with null record; end Derived; ************************************************* Again, keep in mind this is a simplified example. The procedures would do something and the extended types would have other params. This is all well and good. Variables of Derived_Type can only call the version of something that I specified publicly and the overriden one cannot be called. However, variables of More_Derived_Type have public visibility to both versions of Something. I would have hoped that the version hidden by Derived_Type would keep it hidden, but extending the type makes the private procedure visible again. Example main: main.adb ************************************************* with Base; with Derived; use Derived; procedure Main is p : Derived_Param; d : Derived_Type; m : More_Derived_Type; begin d.Something(p); -- Works as expected m.Something(p); -- Causes an error due to ambiguity end Main; ************************************************* Is there a way for me to prevent extending types from making the procedure public again? The error is ambiguous call to "Something"