comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: overriding in private part
Date: Thu, 2 Oct 2008 09:42:28 -0700 (PDT)
Date: 2008-10-02T09:42:28-07:00	[thread overview]
Message-ID: <47e26a8d-d104-46c5-b841-667f6e556792@w7g2000hsa.googlegroups.com> (raw)
In-Reply-To: 45b4a4cc-13f5-4175-9061-9c962e32d762@64g2000hsm.googlegroups.com

On Oct 2, 8:49 am, Maxim Reznik <rezni...@gmail.com> wrote:
> Hi all
>
> Trying to find memory leak in AWS I found strange bug.
>
> Let my explain by example:http://pastebin.mozilla-russia.org/92280
>
> There is a package hierarchy of three packages: A1, A1.A2 and A1.A3.
> And type hierarchy: A1.Base, A2.Child derived from A1.Base, A3.Child
> derived from A2.Child.
>
> A1.Base has primitive procedure P2 in private part of A1.
> A2.Child override P2 with its own P2 in private part of A2.
> A3.Child is expected to override P2 with its own P2 in private part of
> A3, but actually it can't!
> As result A3.P2 is never called in this example. (And never free
> memory in AWS)
>
> My expectation about this code, that A3.P2 override A1.P2 because
> private part of A1 is visible at this place, and A2.P2 invisible here,
> so have no influence here. But A2.P2 hides A1.P2 indeed.
>
> Every type in class A1.Base'Class has P2 primitive subprogram, but any
> child of A2.Child can't override it, because P2 is hidden by A2.P2. It
> seems unnatural to me.
>
> Errors of such kind are very difficult to find.
>
> Is there any way to prevent such errors? (Besides keyword
> *overriding*)

That's one of the reasons "overriding" was added.  Taking a quick look
at AI-218, which proposed this feature, there's a lot of discussion
about private parts.

In general, the language doesn't want to take private declarations of
the parent into account when deciding whether something is
overriding.  E.g.:

package Pak1 is
   type T is tagged private;
private
   -- You're not supposed to care what is here
end Pak1;

package Pak2 is
   type T2 is new Pak1.T with record... end record;
   procedure New_Operation (Obj : in out T2);
end Pak2;

The intent was to define a *new* operation on the child type T2.  It
would be really bad if the behavior changed because the private part
of Pak1 happened to defined its own New_Operation on T, since you're
supposed to be able to write Pak2 and use T as a private type without
knowing anything about the private details of T.  So that's why the
language makes this last New_Operation a "not overriding" operation.

Your case is a little more confusing because, like the above example,
there's an invisible P2 operation of the parent type that shouldn't
affect the behavior, but this is inherited from a P2 operation of the
*grandparent* type that *is* visible in the private part of A1.A3.
Perhaps the compiler should generate a warning about the possible
confusion in this case.  If we didn't have an "overriding" keyword, I
might even go so far as to suggest the language should make this case
illegal, in order to prevent this kind of case from coming up.  But
since "overriding" has been added, you should just use it, and it will
solve the problem.  (Yes, I know, you're working with code written for
Ada 95.  Bummer.)

                                -- Adam






  reply	other threads:[~2008-10-02 16:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-02 15:49 overriding in private part Maxim Reznik
2008-10-02 16:42 ` Adam Beneschan [this message]
2008-10-03  8:52   ` Dmitry A. Kazakov
2008-10-03 15:54     ` Adam Beneschan
2008-10-03 20:29       ` Robert A Duff
2008-10-04  2:28         ` Randy Brukardt
2008-10-04 19:47           ` Robert A Duff
2008-10-05  7:35             ` Dmitry A. Kazakov
2008-10-05 19:57               ` Robert A Duff
2008-10-06  8:50                 ` Dmitry A. Kazakov
2008-10-06 23:32                   ` Randy Brukardt
2008-10-05 11:46             ` stefan-lucks
2008-10-05 20:08               ` Robert A Duff
2008-10-06 23:39                 ` Randy Brukardt
2008-10-02 23:17 ` Randy Brukardt
replies disabled

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