From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: An improved Ada?
Date: Wed, 29 Sep 2004 14:26:30 -0400
Date: 2004-09-29T18:14:53+00:00 [thread overview]
Message-ID: <415afb9d$0$74192$39cecf19@news.twtelecom.net> (raw)
In-Reply-To: 311c6b78.0409290905.15ae255d@posting.google.com
"jn" <jonas.nygren@telia.com> wrote in message
news:311c6b78.0409290905.15ae255d@posting.google.com...
>
>
> package A is
> type X is tagged private;
> type Y is new X with private;
> type Z is new X with private;
>
> type X_Ref is access all X'Class;
> type Y_Ref is access all Y'Class;
> type Z_Ref is access all Z'Class;
>
> function X_A (Xa : access X) return Y_Ref;
> function Z_A (Zv : Z) return Y_Ref;
> private
> type X is tagged
> record
> Xr : X_Ref;
> end record;
> type Y is new X with null record;
> type Z is new X with null record;
> end A;
>
> package body A is
> function X_A (Xa : access X) return Y_Ref is
> begin return null; end;
> function Z_A (Zv : Z) return Y_Ref is
> begin return null; end;
> end A;
>
> with A;
> package B is
> type Y is new A.Y with private;
> type Y_Ref is access all Y'Class;
> type Z is new A.Z with private;
>
> function Y_A (
> Ya : access Y )
> return Integer;
> private
> type Y is new A.Y with
> record
> Value : Integer;
> end record;
> type Z is new A.Z with null record;
> end B;
>
> with A;
> with B;
> procedure T is
> Z : B.Z;
> Yr : B.Y_Ref;
> begin
> Yr := B.Y_Ref ( B.Z_A (Z) );
> Yr := B.Y_Ref (A.X_A (A.X_Ref (Yr)));
> -- why not:
> -- Yr := B.Z_A (Z);
> -- B.Y is a descendant of A.Y that is a descendant of A.X
> -- ret value 'tag' could be checked against Yr tag
> -- why don't the compiler do it, why do I have to do it explicitly
Well, obviously this is wrong. Operation B.Z_A returns type A.Y_Ref, not
B.Y_Ref.
> --
> -- why not:
> -- Yr := B.X_A (Yr);
> -- again, B.Y is a descendant of A.Y that is a descendant of A.X
> -- why is not B.X_A visible, X_A should have been inherited
> -- when A.X_A (Yr) is called, why is not the called dispatched?
> -- I have to convert B.Y_Ref to A.X_Ref explicitly
> -- and again I explicitly have to convert return type
> -- from A.X_Ref to B.Y_Ref, a completely safe conversion
Well, obviously this is wrong. There is no operation X_A that returns type
B.Y_Ref declared in package B. You must be confusing this with the
inherited operation X_A that returns type A.Y_Ref.
next prev parent reply other threads:[~2004-09-29 18:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-27 19:38 An improved Ada? jn
2004-09-27 20:40 ` Matthew Heaney
2004-09-28 20:41 ` Wojtek Narczynski
2004-09-28 22:54 ` Randy Brukardt
2004-09-28 5:45 ` Matthew Heaney
2004-09-29 17:05 ` jn
2004-09-29 18:26 ` Matthew Heaney [this message]
2004-09-29 21:33 ` Randy Brukardt
2004-09-29 22:15 ` tmoran
2004-09-30 16:55 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox