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: 103376,f428ff2031155951 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Equivalent of dynamic_cast (downcast) for tagged types Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <375fb596-ab12-4cb0-a190-53d62b94b2e4@e9g2000vbi.googlegroups.com> <510d779c-d15b-4fc1-b831-bfc578ecdb4b@z3g2000prz.googlegroups.com> Date: Fri, 28 Jan 2011 10:16:20 +0100 Message-ID: <7q5flc9of9ey.19h9nmmzjxqn0.dlg@40tude.net> NNTP-Posting-Date: 28 Jan 2011 10:16:20 CET NNTP-Posting-Host: 8555f161.newsspool1.arcor-online.net X-Trace: DXC=YdMW4Fo<]lROoR1<`=YMgDjhg2m5^1PnP`4Z6[6LHn;2LCV>7enW;^6ZC`4\`mfM[68DC3?njE4FV[d72 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:16761 Date: 2011-01-28T10:16:20+01:00 List-Id: On Thu, 27 Jan 2011 14:35:28 -0800 (PST), Maciej Sobczak wrote: > I have submitted this bug report more than one year ago. Looks like > nobody even bothered to check it. Well, I am not a language lawyer to tell if the behavior (public overriding of a private primitive operation) is legal. > The bug submission states that Adjust is wrongly recognized as > overriding, which it shouldn't be - but now I have hit something more > interesting. It must be overriding because Adjust is a primitive operation. Whether the compiler should allow it to become publicly declared as an overriding is another question. This is a general language design problem, also reappearing in multiple inheritance. Until addressed it will pop up in different places on different occasions. > Why > the heck this Adjust was called on my Controlled_Limited type is a > mystery, but that was easy to confirm: I have added the Adjust > operation for my type, just as in the bug report, and instrumented it > and voila - this proved that the Adjust was really *called*. Maybe the implementation is using the private operation internally. Once you have overridden it, you broke the thing. I agree that the problem must be addressed, by handling MI-like cases properly. But it is a long story. Another long story is that constructor, destructor, ":=" must be built-in primitive operations without Initialize, Finalize, Adjust kludges. AdaCore would not come to the idea of providing Adjust for limited types if there were proper constructors. > But in addition to downcasting, there is an alternative solution which > I have discovered later on, although have not yet tested. > The idea is if I know the actual type (T) in the procedure that > accepts base interface, then apparently I'm working with a closed set > of types, which is actually true. So instead of relying on class-wide > types and dispatching in this particular place I will add another > version of the same operation that accepts T and operates on it. BTW, this is another language design issue. What you want here is dispatching to a narrower class rather than to the leaf. I know no OO language which has this. Arguably many cases of downcast could be eliminated if the application would not forced either to dispatch "prematurely," or not to dispatch at all. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de