comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Preventing private procedure visibility being made public through extension
Date: Sat, 20 May 2017 14:55:28 -0700 (PDT)
Date: 2017-05-20T14:55:28-07:00	[thread overview]
Message-ID: <55306f0a-8b60-4940-af19-e99a74e3fb3b@googlegroups.com> (raw)
In-Reply-To: <88d90508-a6ce-445f-b2a1-519a64a741b2@googlegroups.com>

On Saturday, May 20, 2017 at 4:13:10 PM UTC-4, AdaMagica wrote:
> > 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:

Perhaps a compiler bug, but it is even more than just not 
ambiguous, it cannot call the version of the procedure that I 
put in the private section (for variables of type Derived_Type).  

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 
results (compiler error).  It is acting like the 
procedure is not publicly visible for variable d.

Now if I didn't have a procedure named Something declared, 
it acts as you described.  Is this a compiler bug?

  reply	other threads:[~2017-05-20 21:55 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-20 17:33 Preventing private procedure visibility being made public through extension Jere
2017-05-20 20:13 ` AdaMagica
2017-05-20 21:55   ` Jere [this message]
2017-05-20 20:32 ` Dmitry A. Kazakov
2017-05-20 22:51   ` Jere
2017-05-21  0:51     ` Jere
2017-05-21  9:16       ` Chris Moore
2017-05-21 22:55         ` Jere
2017-05-21  8:44     ` Dmitry A. Kazakov
2017-05-21 12:19       ` J-P. Rosen
2017-05-21 12:53         ` Dmitry A. Kazakov
2017-05-21 20:06       ` Jere
2017-05-21 21:07         ` Dmitry A. Kazakov
2017-05-21 22:28           ` Jere
2017-05-22  8:52             ` Dmitry A. Kazakov
2017-05-22 13:33               ` AdaMagica
2017-05-22 13:43           ` AdaMagica
2017-05-22 21:17         ` Randy Brukardt
2017-05-25  4:06           ` Jere
2017-05-25 19:39             ` Randy Brukardt
2017-05-25 22:53               ` Jere
2017-05-25 22:57                 ` Jere
2017-05-26 20:46                 ` Randy Brukardt
2017-05-26 22:35                   ` Simon Wright
2018-05-20 11:22                     ` Simon Wright
2018-05-20 12:03                       ` Jere
2017-05-26 22:58                   ` Jeffrey R. Carter
2017-05-30 21:15                     ` Randy Brukardt
2017-06-02  1:07                       ` Jere
2017-06-02  7:31                         ` Dmitry A. Kazakov
2017-06-02  8:09                         ` Mark Lorenzen
2017-06-02 11:31                         ` Simon Wright
2017-05-22 21:12   ` Randy Brukardt
2017-05-23  7:38     ` Dmitry A. Kazakov
2017-05-21 18:14 ` Robert Eachus
2017-05-21 20:21   ` Jere
2017-05-21 21:09     ` Jeffrey R. Carter
2017-05-21 22:46       ` Jere
2017-05-22 21:24         ` Jeffrey R. Carter
2017-05-25  3:45           ` Jere
2017-05-21 21:20     ` Dmitry A. Kazakov
2017-05-21 21:45       ` Jere
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox