comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada design bug or GNAT bug?
Date: Fri, 3 Jul 2015 22:11:18 -0500
Date: 2015-07-03T22:11:18-05:00	[thread overview]
Message-ID: <mn7isn$ot6$1@loke.gir.dk> (raw)
In-Reply-To: 56pbwdnfce0k$.5et1apcv65k9.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:56pbwdnfce0k$.5et1apcv65k9.dlg@40tude.net...
> On Fri, 3 Jul 2015 12:33:07 -0500, Randy Brukardt wrote:
>
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>
>>> But even if you convert to the class-wide you don't get visibility of 
>>> the
>>> operation. In the scenario:
>>>
>>>   type T3 is new T1 with private;
>>> private
>>>   type T3 is new T2 with null record; -- Legal!
>>>
>>> a public client could not convert a T3 object to T2'Class. Could it?
>>
>> No, but a private client can, and if you have a public type T4 derived 
>> from
>> T3, it would not have the function operation.
>>
>> package P2 is
>>    type T3 is new T1 with private;
>>    procedure Do_It (X : inT3);
>> private
>>    type T3 is new T2 with null record; -- Legal!
>> end P2;
>>
>> with P2;
>> package P3 is
>>    type T4 is new P2.T3 with C : Character; end record; -- No defined F 
>> here.
>
> This must be illegal. The compiler shall require (unless T4 is abstract):
>
> 1. That the private part of the package had a full view of P2.T3
>
> 2. F overridden there.

But of course that breaks privacy: T4 knows nothing about the full type of 
T3 or any private operations it may have. If you mean that such a derivation 
should *always* be illegal, well, perhaps that would have been better, but 
its clearly too late (it has been legal for 20+ years, there's plenty of 
code that depends on deriving from a non-visible private type -- Claw has a 
number of such types [from sibling inheritance]).

>>> We have ugly executable precondition code at the declaration side. Why 
>>> not
>>> to allow this for functions?
>>
>> I don't understand what you mean. An expression function can be given as 
>> the
>> overriding, but that doesn't help if you don't have the needed visibility 
>> to
>> see the components in question (an aggregate is only legal if no private
>> types are involved -- we tried to find a way to relax that for Ada 2005, 
>> but
>> it just got way too messy).
>
> That is the idea, to do it without visibility. When you inherit bodies of
> procedures you don't need visibility. You "convert" parameters (view
> conversion, does nothing) and call the parent's body.
>
> Similarly we could compose a body of an invisible operation. In the 
> example
> above the invisible operation is F, when we derive T4 from T3 above. We do
> not need to know if F exists in order to say something like: if there is
> any primitive function returning T3 override it by adding 'A' for the
> component C. That would make
>
> package P3 is
>   type T4 is new T3 with record
>      C : Character;
>   end record
>      with overriding function C => 'A';
>          -- Imaginary syntax for automated function overriding aspect
>
> We could allow formal parameters of the aspect to be matched against
> parameters of overridden functions and used in the aggregate. We could
> allow a name of a body to initialize the type extension instead of an
> aggregate in order to move the mess into the package body instead of
> exposing it in the declaration scope, etc.

I had suggested something on this line (but simpler): simply flag if using 
the default values of the extension components are enough for constructing 
such values (they often will be). But it didn't get much traction.

You could of course submit something like the above to Ada-Comment. (Make 
sure to include a good problem description if you do; the problem is usually 
more important than the suggested solution.) At the least, it would add 
weight to the existing problem.

                              Randy.





  reply	other threads:[~2015-07-04  3:11 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-20 18:55 Ada design bug or GNAT bug? Dmitry A. Kazakov
2015-06-21  2:42 ` Randy Brukardt
2015-06-21  6:47   ` Dmitry A. Kazakov
2015-06-22 17:39     ` Randy Brukardt
2015-06-22 18:16       ` Dmitry A. Kazakov
2015-06-23 11:00         ` G.B.
2015-06-23 14:27           ` Dmitry A. Kazakov
2015-06-23 11:45         ` G.B.
2015-06-23 14:30           ` Dmitry A. Kazakov
2015-07-02 22:22         ` Randy Brukardt
2015-07-03  8:02           ` Dmitry A. Kazakov
2015-07-03 17:33             ` Randy Brukardt
2015-07-03 21:34               ` Dmitry A. Kazakov
2015-07-04  3:11                 ` Randy Brukardt [this message]
2015-07-04 12:14                   ` Dmitry A. Kazakov
2015-07-05  0:53                     ` Randy Brukardt
2015-06-22 18:27       ` Shark8
2015-06-23 11:51         ` vincent.diemunsch
2015-06-23 19:55           ` Shark8
2015-06-23 13:06         ` vincent.diemunsch
2015-06-23 14:30           ` David Botton
2015-06-23 15:57             ` Niklas Holsti
2015-06-23 16:01               ` G.B.
2015-06-23 18:05               ` David Botton
2015-06-23 19:38               ` David Botton
2015-06-23 14:38           ` Dmitry A. Kazakov
2015-06-23 16:57             ` Vincent
2015-06-23 17:15               ` Dmitry A. Kazakov
2015-06-23 19:14                 ` vincent.diemunsch
2015-06-23 19:33                   ` Dmitry A. Kazakov
2015-06-23 17:42           ` Jeffrey R. Carter
2015-07-02 22:06           ` Randy Brukardt
2015-07-04  1:52             ` Shark8
2015-07-04  3:24               ` Randy Brukardt
2015-07-04 11:02                 ` Build-in-place semantics? (Was: Ada design bug or GNAT bug?) Jacob Sparre Andersen
2015-07-04 12:15                   ` Dmitry A. Kazakov
2015-07-05  0:45                     ` Randy Brukardt
2015-07-05  7:10                       ` Dmitry A. Kazakov
2015-07-05  0:40                   ` Randy Brukardt
2015-07-04 14:05                 ` Ada design bug or GNAT bug? Bob Duff
2015-07-04  7:46               ` Simon Wright
2015-07-04 12:00                 ` Björn Lundin
2015-07-05  0:48                   ` Randy Brukardt
2015-07-06 12:37             ` Vincent
2015-07-06 20:05               ` Randy Brukardt
2015-07-07  8:06               ` Dmitry A. Kazakov
replies disabled

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