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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!postnews.google.com!w7g2000hsa.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: overriding in private part Date: Thu, 2 Oct 2008 09:42:28 -0700 (PDT) Organization: http://groups.google.com Message-ID: <47e26a8d-d104-46c5-b841-667f6e556792@w7g2000hsa.googlegroups.com> References: <45b4a4cc-13f5-4175-9061-9c962e32d762@64g2000hsm.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1222965749 30139 127.0.0.1 (2 Oct 2008 16:42:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 2 Oct 2008 16:42:29 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w7g2000hsa.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2197 Date: 2008-10-02T09:42:28-07:00 List-Id: On Oct 2, 8:49 am, Maxim Reznik 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