comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Equivalent of dynamic_cast (downcast) for tagged types
Date: Fri, 28 Jan 2011 10:16:20 +0100
Date: 2011-01-28T10:16:20+01:00	[thread overview]
Message-ID: <7q5flc9of9ey.19h9nmmzjxqn0.dlg@40tude.net> (raw)
In-Reply-To: 510d779c-d15b-4fc1-b831-bfc578ecdb4b@z3g2000prz.googlegroups.com

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



  parent reply	other threads:[~2011-01-28  9:16 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 15:46 Equivalent of dynamic_cast (downcast) for tagged types Maciej Sobczak
2011-01-27 16:18 ` Dmitry A. Kazakov
2011-01-27 17:10   ` J-P. Rosen
2011-01-27 17:35     ` Dmitry A. Kazakov
2011-01-27 22:49     ` Maciej Sobczak
2011-01-27 17:50   ` Georg Bauhaus
2011-01-27 22:35   ` Maciej Sobczak
2011-01-28  5:07     ` Yannick Duchêne (Hibou57)
2011-01-28  9:16     ` Dmitry A. Kazakov [this message]
2011-01-28 13:11       ` AdaMagica
2011-01-28 14:13         ` Dmitry A. Kazakov
2011-01-28 23:51           ` Randy Brukardt
2011-01-29  0:55             ` Adam Beneschan
2011-01-28 16:44       ` Adam Beneschan
2011-01-28 17:21         ` Dmitry A. Kazakov
2011-01-29  0:12           ` Randy Brukardt
2011-01-29  8:47             ` Dmitry A. Kazakov
2011-01-28 17:33         ` Adam Beneschan
2011-01-28 15:13     ` Maciej Sobczak
2011-01-28 17:47       ` Robert A Duff
2011-01-28 22:04         ` Maciej Sobczak
2011-01-30 20:22           ` Stephen Leake
2011-01-31  9:04             ` AdaCore, user community and communication channels Maciej Sobczak
2011-01-31 10:42               ` Georg Bauhaus
2011-01-27 19:33 ` Equivalent of dynamic_cast (downcast) for tagged types Adam Beneschan
replies disabled

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