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, WEIRD_PORT autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.98.141.152 with SMTP id p24mr6498844pfk.41.1495317328697; Sat, 20 May 2017 14:55:28 -0700 (PDT) X-Received: by 10.157.35.104 with SMTP id k37mr342015otd.14.1495317328552; Sat, 20 May 2017 14:55:28 -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!67no1015714itx.0!news-out.google.com!m134ni4240itb.0!nntp.google.com!67no1014861itx.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 20 May 2017 14:55:28 -0700 (PDT) In-Reply-To: <88d90508-a6ce-445f-b2a1-519a64a741b2@googlegroups.com> 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 References: <88d90508-a6ce-445f-b2a1-519a64a741b2@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <55306f0a-8b60-4940-af19-e99a74e3fb3b@googlegroups.com> Subject: Re: Preventing private procedure visibility being made public through extension From: Jere Injection-Date: Sat, 20 May 2017 21:55:28 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:46827 Date: 2017-05-20T14:55:28-07:00 List-Id: On Saturday, May 20, 2017 at 4:13:10 PM UTC-4, AdaMagica wrote: > > with Base; > >=20 > > package Derived is > > =20 > > type Derived_Param is new Base.Base_Param with null record; > > =20 > > type Derived_Type is new Base.Base_Type with private; > > =20 > > procedure Something > > (Obj : in out Derived_Type;=20 > > Value : Derived_Param'Class) > > is null; > > =20 > > private > > =20 > > type Derived_Type is new Base.Base_Type with null record; > > =20 > > overriding > > procedure Something > > (Obj : in out Derived_Type;=20 > > Value : Base.Base_Param'Class)=20 > > is null; > > =20 > > end Derived; >=20 > Here you are wrong. Hiding the overriding does not prevent the client fro= m 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.) >=20 > > ************************************************* > >=20 > > This is all well and good. Variables of Derived_Type=20 > > can only call the version of something that I specified=20 > > publicly and the overriden one cannot be called. >=20 > As I said, this is wrong. >=20 > >=20 > > However, variables of More_Derived_Type have public=20 > > visibility to both versions of Something. I would=20 > > have hoped that the version hidden by Derived_Type=20 > > would keep it hidden, but extending the type makes > > the private procedure visible again. > >=20 > > Example main: > >=20 > > main.adb > > ************************************************* > > with Base; > > with Derived; use Derived; > >=20 > > procedure Main is > > p : Derived_Param; > > d : Derived_Type; > > m : More_Derived_Type; > > begin > > d.Something(p); -- Works as expected >=20 > I think your compiler is in error here. This call is (IMHO) also ambiguou= s. > Both of these operations are visible here: Perhaps a compiler bug, but it is even more than just not=20 ambiguous, it cannot call the version of the procedure that I=20 put in the private section (for variables of type Derived_Type). =20 If I declare a variable: b : Base.Base_Param; and try to call d.Something(b); It will fail with an error: Expected type "Derived_Param'Class" defined at derived.ads:5 expected type "Derived_Param'Class" defined at derived.ads:5 found type "Base_Param" defined at base.ads:3 I even tried casting b to Base_Param'Class with similar=20 results (compiler error). It is acting like the=20 procedure is not publicly visible for variable d. Now if I didn't have a procedure named Something declared,=20 it acts as you described. Is this a compiler bug?