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,33ed4ca582c945fc X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!x1g2000prh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Limited returns Date: Mon, 23 Jun 2008 08:15:12 -0700 (PDT) Organization: http://groups.google.com Message-ID: <7ab69a86-cfcf-4dba-9280-e0fce906ed76@x1g2000prh.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1214234112 2335 127.0.0.1 (23 Jun 2008 15:15:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 23 Jun 2008 15:15:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x1g2000prh.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 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) Xref: g2news1.google.com comp.lang.ada:819 Date: 2008-06-23T08:15:12-07:00 List-Id: On Jun 23, 7:21 am, "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. It's illegal, but hopefully not for long. See: http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AI05s/AI05-0032-1.TXT?rev=1.4 Perhaps you could ask your compiler to go ahead and implement that AI (or at least the part of it that allows the specific return type as you've done). I think it was just an oversight in Ada 2005 not to allow this. > 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? Probably. Semantically, the expression the right of := has type "S", so there shouldn't be any problem with a self-reference in that expression. However, since S is limited, the language requires the aggregate to be built in place. My guess is that when the compiler implements build-in-place in this case, it starts believing the type of the aggregate is I'Class instead of S, which leads to the wrong result. Anyway, I don't see anything illegal about this so I think it's a compiler bug. -- Adam