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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,86c76377d1077f30 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!b28g2000cwb.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Casting from interface type Date: 27 Jul 2006 18:29:01 -0700 Organization: http://groups.google.com Message-ID: <1154050141.462907.39690@b28g2000cwb.googlegroups.com> References: <44c94166$0$11790$626a54ce@news.free.fr> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1154050146 19711 127.0.0.1 (28 Jul 2006 01:29:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 28 Jul 2006 01:29:06 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: b28g2000cwb.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:5977 Date: 2006-07-27T18:29:01-07:00 List-Id: 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