comp.lang.ada
 help / color / mirror / Atom feed
From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: Casting from interface type
Date: 27 Jul 2006 18:29:01 -0700
Date: 2006-07-27T18:29:01-07:00	[thread overview]
Message-ID: <1154050141.462907.39690@b28g2000cwb.googlegroups.com> (raw)
In-Reply-To: 44c94166$0$11790$626a54ce@news.free.fr

Yves Bailly wrote:
> Hello all,
>
> Please consider this small code :
> --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
> procedure Proc is
>    type I is interface;
>    type T is tagged null record;
>    type DT is new T and I with null record;
>
>    var_t: T;
>    var_tc: T'Class := var_t;
>
>    procedure Conv(p: in I'Class) is
>    begin
>       if p in T'Class
>       then
>          var_t := T(p);
>          var_tc := T'Class(p);
>       end if;
>    end Conv;
>
>    var_dt: DT;
>
> begin
>
>    Conv(var_dt);
>
> end Proc;
> --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
>
> Using the latest GNAT 2006, I receive the following errors:
> proc.adb:14:19: invalid tagged conversion, not compatible with
> type "I'Class" defined at line 3

Type T is not descended from I, so there cannot be any object in
I'Class that has type T.  However, the following should be legal,
although GNAT probably won't accept it (see below):

    var_t := T (T'Class (p));

> proc.adb:15:21: invalid tagged conversion, not compatible with
> type "I'Class" defined at line 3

I think this is legal and GNAT is wrong.  My printed copy of
4.6(23.1/2) says that type conversions between *any* two class-wide
types are legal if one of them has an interface type as its specific
type, even if the other one doesn't have an interface ancestor, because
some type in the class *could* have an interface ancestor (as DT does
in your example).  I tried to check to make sure this section hasn't
changed since I printed it, but unfortunately www.adaic.com is down
right now.

                           -- Adam




  reply	other threads:[~2006-07-28  1:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-27 22:42 Casting from interface type Yves Bailly
2006-07-28  1:29 ` Adam Beneschan [this message]
2006-07-28  5:46   ` Yves Bailly
2006-07-28 12:06     ` Javier Miranda - jmiranda
2006-07-28  4:32 ` Jeffrey R. Carter
replies disabled

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