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.99.44.197 with SMTP id s188mr8097749pgs.61.1495311188775; Sat, 20 May 2017 13:13:08 -0700 (PDT) X-Received: by 10.157.14.91 with SMTP id n27mr334989otd.8.1495311188727; Sat, 20 May 2017 13:13:08 -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!67no999202itx.0!news-out.google.com!v18ni4095ita.0!nntp.google.com!67no999198itx.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 20 May 2017 13:13:08 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=84.131.51.223; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf NNTP-Posting-Host: 84.131.51.223 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <88d90508-a6ce-445f-b2a1-519a64a741b2@googlegroups.com> Subject: Re: Preventing private procedure visibility being made public through extension From: AdaMagica Injection-Date: Sat, 20 May 2017 20:13:08 +0000 Content-Type: text/plain; charset="UTF-8" Xref: news.eternal-september.org comp.lang.ada:46825 Date: 2017-05-20T13:13:08-07:00 List-Id: > 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; > > 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; > > end Derived; Here you are wrong. Hiding the overriding does not prevent the client from calling the operation. It nearly makes no difference whether you override an inherited operation in the public or in the private part. (There are a few syntactic diffrences though.) > ************************************************* > > 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. As I said, this is wrong. > > 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 I think your compiler is in error here. This call is (IMHO) also ambiguous. Both of these operations are visible here: not overriding procedure Something (Obj : in out Derived_Type; Value : Derived_Param'Class); overriding procedure Something (Obj : in out Derived_Type; Value : Base.Base_Param'Class); Since your parameter d belongs to both classwide types, it's impossible to decide to which class it has to be converted (implicitly). > 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"