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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,735c710b5e547bad X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.240.101 with SMTP id vz5mr2895027pbc.4.1342110861279; Thu, 12 Jul 2012 09:34:21 -0700 (PDT) Path: l9ni11515pbj.0!nntp.google.com!news2.google.com!goblin3!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada 2005 puzzle Date: Thu, 12 Jul 2012 18:34:14 +0200 Organization: cbb software GmbH Message-ID: <1f9q6vk5z2r3t$.1hayo9rmxfwu7$.dlg@40tude.net> References: <1arp60wtxes8h$.1qs6bt732ztgp.dlg@40tude.net> <030cde76-7435-405d-9f12-ac7f730ecab8@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: 9A8bJrx4NhDLcSmbrb6AdA.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-07-12T18:34:14+02:00 List-Id: On Thu, 12 Jul 2012 08:48:05 -0700 (PDT), Adam Beneschan wrote: > On Thursday, July 12, 2012 5:54:08 AM UTC-7, Dmitry A. Kazakov wrote: >> Here is a simplified case illustrating an issue with constructing functions >> and limited aggregates: >> >> -------------------------------------------- package P >> with Ada.Finalization; >> package P is >> type T (<>) is new Ada.Finalization.Limited_Controlled with private; >> function Create return T; >> private >> type T is new Ada.Finalization.Limited_Controlled with null record; >> end P; >> - - - - - - - - - - - - - - - - - - - - - - - - >> package body P is >> function Create return T is >> begin >> return (Ada.Finalization.Limited_Controlled with null record); >> end Create; >> end P; >> -------------------------------------------- package Q >> with P; use P; >> package Q is >> type S is abstract new T with null record; >> type R is new S with null record; >> overriding function Create return R; >> end Q; >> - - - - - - - - - - - - - - - - - - - - - - - - >> package body Q is >> function Create return R is >> begin >> return (T'(Create) with null record); -- Error! >> end Create; >> end Q; >> >> Is there a way to implement Create (without compromising the package P)? > > Well, there seem to be a couple bogus things about your example: (1) your > extension aggregate in Q doesn't have any additional components, Of course it does not work with components too. Actually it never works if the depth of types hierarchy >2. Initially I thought that the problem is because there was an abstract type in between. > and (2) the title of your post is "Ada 2005 puzzle". Sorry for "puzzle." It is just because there is no way to know in advance if it will be possible to create objects of a derived limited type using the constructing function of the/a parent. Furthermore inventing an "aggregate" for a limited type with ancestors is always a challenge with about 70% chances to lose. > However, if you were to make R (or S) a type extension with at least one > new component, rather than a null extension, there would be a problem. Thus with components it is impossible per language design? The motivation of the example is enforcing initialization (with parameters) on a limited ancestor type. I gather, from your post, that this is fundamentally impossible in Ada. So far it was somehow possible in Ada 2005, with, as I said 30% chances of success. > If this is a real issue (and not simply a hypothetical one), then maybe > ARG would be open to a proposed change like this. Well, it is an on-going battle of finding a work-around with least losses. Because the problem appears only later in other packages, when the train already left the station. (I never doubted that limited aggregates were broken, but I didn't think that nobody intended them to work.) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de