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 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.36.79 with SMTP id k76mr9925217iok.32.1511787394759; Mon, 27 Nov 2017 04:56:34 -0800 (PST) X-Received: by 10.157.11.207 with SMTP id 73mr1675964oth.2.1511787394658; Mon, 27 Nov 2017 04:56:34 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!peer01.am4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!i6no7391779itb.0!news-out.google.com!193ni4482iti.0!nntp.google.com!i6no7391778itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 27 Nov 2017 04:56:34 -0800 (PST) In-Reply-To: <102d4df8-d392-4100-9a37-c49705397e4e@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.208.22; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.208.22 References: <4db43571-7f86-4e73-8849-c41160927703@googlegroups.com> <6496a10f-c97e-4e42-b295-2478ad464b2f@googlegroups.com> <6106dfe6-c614-4fc1-aace-74bf8d7435e3@googlegroups.com> <102d4df8-d392-4100-9a37-c49705397e4e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Extending a third party tagged type while adding finalization From: Jere Injection-Date: Mon, 27 Nov 2017 12:56:34 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Body-CRC: 3144486647 X-Received-Bytes: 4210 Xref: reader02.eternal-september.org comp.lang.ada:49186 Date: 2017-11-27T04:56:34-08:00 List-Id: On Monday, November 27, 2017 at 4:46:09 AM UTC-5, AdaMagica wrote: > Am Sonntag, 26. November 2017 18:33:50 UTC+1 schrieb Jere: > > Starting Test_Limited_Controlled_Mixin > > LC1: Initialize > > Extension: Initialize > > LC2: Initialize > > Hm, I'm astonished about the sequence here. Components should be initialized first, then the containing object, RM 7.6(12). > > LC2: Initialize > Extension: Initialize > > Thus the extension has completely defined components when initialize is called. > In your example, the component LC2 is still uninitialized when extension is initialized. This looks like a bug to me. > > Finalization is of course in the reverse order. If I understand you correctly, then I think everything may be working as intended. I didn't provide the code for for Limited_Controlled_Mixin. It is similar to the code you linked to me but instead has a classwide access for Base.Instance as opposed to a normal access to Base.Instance. It also does both Initialize and Finalize. In essence: type Limited_Controlled is new Limited_Base with private; procedure Initialize(Self : in out Limited_Controlled) is null; procedure Finalize(Self : in out Limited_Controlled) is null; private type Proxy(Reference : not null access Limited_Controlled'Class) is new Ada.Finalization.Limited_Controlled with null record; procedure Finalize(Self : in out Proxy); procedure Initialize(Self : in out Proxy); type Limited_Controlled is new Limited_Base with record Impl : Proxy(Limited_Controlled'Access); end record; procedure Finalize(Self : in out Proxy) is begin Reference.Finalize; end Finalize; procedure Initialize(Self : in out Proxy) is begin Reference.Initialize; end Initialize; So based on the RM section you quoted, the I think the sequence for an inheritance tree of: Base.Instance || Limited_Controlled_Mixin.Limited_Controlled || Extension.Instance is: 1. Components of Base.Instance 2. Base.Instance object 3. Components of Limited_Controlled_Mixin.Limited_Controlled => Classwide access to itself 4. Limited_Controlled_Mixin.Limited_Controlled object 5. Components of Extension.Instance 6. Extension.Instance object That's assuming an ancestor tagged type is consider a component of the descendant. My classwide access in #3 is dispatching to the Extension object itself, circumventing the order. I didn't think my design through well enough when I did that. The intent was to be able to provide "overridable" Initialize and Finalize to descendants of the mixin which would be called automatically, but now I don't think that is possible in a safe way.