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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,33ed4ca582c945fc X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!p25g2000hsf.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Egil_H=F8vik?= Newsgroups: comp.lang.ada Subject: Re: Limited returns Date: Thu, 26 Jun 2008 05:35:34 -0700 (PDT) Organization: http://groups.google.com Message-ID: <449184cd-f581-46ad-810f-dddd5555ebad@p25g2000hsf.googlegroups.com> References: NNTP-Posting-Host: 193.71.180.107 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1214483735 14626 127.0.0.1 (26 Jun 2008 12:35:35 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 26 Jun 2008 12:35:35 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p25g2000hsf.googlegroups.com; posting-host=193.71.180.107; posting-account=P68zsgoAAABKpXKMUuwuUZ_RfBk1kZfB User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:894 Date: 2008-06-26T05:35:34-07:00 List-Id: On Jun 23, 4:21 pm, "Dmitry A. Kazakov" wrote: > Let's consider this: > > with Ada.Finalization; > procedure Test_Limited_Stuff is > type I is limited interface; > > type T is new Ada.Finalization.Limited_Controlled with record > A : Integer; > end record; > > type S is new T and I with record > Self : not null access S'Class := S'Unchecked_Access; > end record; > > function Factory return I'Class is > begin > return X : S; > -- GNAT: wrong type for return_subtype_indication > end Factory; > begin > null; > end Test_Limited_Stuff; > > Is it illegal? I am surprised why? S is in I'Class. > > OK, if that is indeed illegal, then let's make another try: > > function Factory return I'Class is > begin > return X : I'Class := S'(T with others => <>); > -- GNAT: expected an access type with designated type "S'Class" defined ... > -- found an access type with designated type "I'Class" defined ... > end Factory; > > ...still illegal, but more interesting. It seems that a Rosen's trick > member cannot be initialized because the object's type is more general than > the designated access type. It should not be so. A compiler bug? > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de If the goal is to make this compile, do this: function Factory return I'Class is function S_Factory return S is begin return X : S; end S_Factory; begin return X : I'Class := S_Factory; end Factory; But then it seems that dispatching on methods of I is broken... (at least I couldn't get it to work with an abstract procedure. Didn't dispatch to the overridden procedure implemented by S or give an error...)