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: a07f3367d7,5a88548f1bcf3510,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Received: by 10.216.216.141 with SMTP id g13mr86476wep.3.1353056866789; Fri, 16 Nov 2012 01:07:46 -0800 (PST) Path: ha8ni292813wib.1!nntp.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!news-hub.siol.net!news1.t-com.hr!newsfeed.CARNet.hr!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Overring function and its returned type Date: Fri, 09 Nov 2012 08:13:23 +0100 Organization: Ada @ Home Message-ID: NNTP-Posting-Host: aWaWeUaBdaj2Zzc04J1v5A.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.02 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2012-11-09T08:13:23+01:00 List-Id: I feel a bit disappointed with a construct I never attempted before, and= = which seems to not be valid according to GNAT, which I believe is not = wrong, as I can't recall to have read it's allowed. First a snippet, the= n = some comments. procedure Ex is -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D package P1 is type R is interface; type T is interface; not overriding function F (E : T) return R'Class is abstract; end; -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D package P2 is type R is interface and P1.R; type T is interface and P1.T; overriding function F (E : T) return R'Class -- Not overriding :-( is abstract; end; -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D package P3 is type R is new P1.R with null record; type T is new P1.T with null record; overriding function F (E : T) return P1.R'Class; end; -- ---------------------------------------- package body P3 is overriding function F (E : T) return P1.R'Class is X : R; begin return X; -- This is OK end; end; -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D begin null; end Ex; In `P2`, `R` inherits from `P1.R`, so belongs to `P1.R'Class`, and is a = = value returned type for an concrete function `F`, as `P3` shows. But GNA= T = reject it, complaining `P2.F` is not overriding (by the way, the example= = also shows how much it is safer to always add an =E2=80=9C[not] overridi= ng=E2=80=9D = qualification to dispatching subprograms). As `P2.R'Class` is compatible with `P1.R'Class`, why not allow this for = an = overriding function? This case makes me think of the one fixed by Ada = 2012, about the returned class wide type of a function and the extended = = returned statement, explained in [Extended return = statements](http://www.ada-auth.org/standards/12rat/html/Rat12-4-6.html)= . If that's not allowed with good reasons, then what are these? A work around could be to use overloading instead of overriding, but tha= t = may cause troubles when there is no other arguments to the function, in = = which case this will probably looks ambiguous in some contexts. This can= = also cause issues when there are predicates using `F` in `P1`. I could = give a tiny example of such a case if someone need one to see why it may= = be an issue. If that could be OK to allow overriding functions to change their return= = type to a compatible type when this type is class wide, then is there a = = chance to add it as a last minute change for Ada 2012? -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity