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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,45c4e8c210d7ef0d X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!goblin3!goblin1!goblin.stu.neva.ru!eweka.nl!hq-usenetpeers.eweka.nl!193.201.147.81.MISMATCH!feed.xsnews.nl!border-1.ams.xsnews.nl!tudelft.nl!txtfeed1.tudelft.nl!newsfeed.kpn.net!newsfeed.kpn.net!npeer.de.kpn-eurorings.net!npeer-ng1.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Another problem with "interface" Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Mon, 16 Feb 2009 14:29:50 +0100 Message-ID: NNTP-Posting-Date: 16 Feb 2009 14:29:50 CET NNTP-Posting-Host: 54c40e39.newsspool4.arcor-online.net X-Trace: DXC=l=`OERhDR2^=>bdbdS?M0Y4IUKkgRE0>jkYDRV9U X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4628 Date: 2009-02-16T14:29:50+01:00 List-Id: On Mon, 16 Feb 2009 09:53:59 +0000, Robert_Matthews wrote: > In using interface types with GNAT I have encountered another problem. > Consider the following package: > > package Test is > > type A_Type is limited interface; > > procedure P (A : in out A_Type; D : Integer) is abstract; > > protected type New_A_Type is new A_Type > with > procedure P (D : Integer); > -- other subprograms... > private > F : Integer; > end New_A_Type; > > function Set_A return New_A_Type; > > end Test; > > GNAT gives an error for the function Set_A: > "operation can be dispatching in only one type", > which leaves me mystified. Am I making another > dumb mistake? Please help! > > The version of GNAT is GNAT GPL 2008 (20080521). This looks like a compiler bug to me. The compiler thinks that Set_A is a protected function of New_A_Type and thus has the hidden argument New_A_Type and the result New_A_Type, so it complains. But protected type is not tagged so Set_A cannot be dispatching. However you can trick the compiler by ensuring that Set_A declaration were beyond the freezing point of New_A_Type (whatever that might mean for a protected type). For example: type A_Type is limited interface; procedure P (A : in out A_Type; D : Integer) is abstract; protected type New_A_Type is new A_Type with procedure P (D : Integer); -- other subprograms... private F : Integer; end New_A_Type; package Foo is -- Package brackets around it function Set_A return New_A_Type; end Foo; A more logical way to do it would be: function Set_A return New_A_Type'Class; Alas, this does not work, because there seem to be no way to create New_A_Type'Class, since New_A_Type is protected. However you could use A_Type'Class instead: function Set_A return A_Type'Class; P.S. Returning New_A_Type from a function is tricky because it is limited, yet does not have aggregates. You can use the return statement to work this around: function Set_A return New_A_Type is begin return Result : New_A_Type do null; end return; end Set_A; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de