* Casting from interface type
@ 2006-07-27 22:42 Yves Bailly
2006-07-28 1:29 ` Adam Beneschan
2006-07-28 4:32 ` Jeffrey R. Carter
0 siblings, 2 replies; 5+ messages in thread
From: Yves Bailly @ 2006-07-27 22:42 UTC (permalink / raw)
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
proc.adb:15:21: invalid tagged conversion, not compatible with
type "I'Class" defined at line 3
Please, can someone tell me what am I doing wrong ?
Thanks in advance for your time.
Best regards,
--
(o< | Yves Bailly : http://kafka-fr.net | -o)
//\ | Linux Dijon : http://www.coagul.org | //\
\_/ | | \_/`
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Casting from interface type
2006-07-27 22:42 Casting from interface type Yves Bailly
@ 2006-07-28 1:29 ` Adam Beneschan
2006-07-28 5:46 ` Yves Bailly
2006-07-28 4:32 ` Jeffrey R. Carter
1 sibling, 1 reply; 5+ messages in thread
From: Adam Beneschan @ 2006-07-28 1:29 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Casting from interface type
2006-07-27 22:42 Casting from interface type Yves Bailly
2006-07-28 1:29 ` Adam Beneschan
@ 2006-07-28 4:32 ` Jeffrey R. Carter
1 sibling, 0 replies; 5+ messages in thread
From: Jeffrey R. Carter @ 2006-07-28 4:32 UTC (permalink / raw)
Yves Bailly wrote:
>
> Please, can someone tell me what am I doing wrong ?
You are using the word "casting", which is not an Ada term. Note that it
is not used in the error messages you quote.
--
Jeff Carter
"Perfidious English mouse-dropping hoarders."
Monty Python & the Holy Grail
10
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Casting from interface type
2006-07-28 1:29 ` Adam Beneschan
@ 2006-07-28 5:46 ` Yves Bailly
2006-07-28 12:06 ` Javier Miranda - jmiranda
0 siblings, 1 reply; 5+ messages in thread
From: Yves Bailly @ 2006-07-28 5:46 UTC (permalink / raw)
Adam Beneschan wrote:
>> 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.
This makes sense to me?
> 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.
Just checked, it hasn't changed since when I downloaded it. This is
this precise clause which made me wondering if I misunderstood
something. Well, maybe I'll fill a bug report...
Thanks for your help.
Regards,
--
(o< | Yves Bailly : http://kafka-fr.net | -o)
//\ | Linux Dijon : http://www.coagul.org | //\
\_/ | | \_/`
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Casting from interface type
2006-07-28 5:46 ` Yves Bailly
@ 2006-07-28 12:06 ` Javier Miranda - jmiranda
0 siblings, 0 replies; 5+ messages in thread
From: Javier Miranda - jmiranda @ 2006-07-28 12:06 UTC (permalink / raw)
To: Yves Bailly; +Cc: comp.lang.ada
On Fri, 28 Jul 2006, Yves Bailly wrote:
>> 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.
Yves,
You are correct. This problem was detected after the distribution of
GAP-2006 and it is already fixed in the development version of the GNAT
compiler.
--- Javier Miranda
"A Detailed Description of the GNU Ada Run-Time", J.Miranda
Free book available at http://www.iuma.ulpgc.es/users/jmiranda/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-07-28 12:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-27 22:42 Casting from interface type Yves Bailly
2006-07-28 1:29 ` Adam Beneschan
2006-07-28 5:46 ` Yves Bailly
2006-07-28 12:06 ` Javier Miranda - jmiranda
2006-07-28 4:32 ` Jeffrey R. Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox