comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: A problem with "interface"
Date: Thu, 5 Feb 2009 08:14:56 -0800 (PST)
Date: 2009-02-05T08:14:56-08:00	[thread overview]
Message-ID: <b536e8fe-d10b-41a4-847c-05ee4c90bd00@y23g2000pre.googlegroups.com> (raw)
In-Reply-To: zvGdneFPpt7YnRbUnZ2dnUVZ8uednZ2d@posted.plusnet

On Feb 5, 7:05 am, Robert_Matthews <igno...@ramatthews.free-
online.co.uk> wrote:
> In using interface types with GNAT I have encountered a problem.
> Consider the following packages:
>
> package Int is
>
>    type A is interface;
>    type B is interface;
>
>    procedure P (Param1 : A; Param2 : B'Class) is abstract;
>
> end Int;
>
> with Int;
> package Client is
>
>    type Client_A is new Int.A with null record;
>    type Client_B is new Int.B with null record;
>
>    overriding
>    procedure Client_P (Param1 : Client_A; Param2 : Client_B'Class);
>
> end Client;
>
> On compiling, GNAT says "Client_P" does not override anything.
> Am I making a dumb mistake here - or is it GNAT?

You're making a mistake, but I'm hesitant to call it a "dumb" one.
When you declare Client_A, the package implicitly declares inherited
operations, which are inherited from primitive operations of Int.A.
One of those is Client_P, and so you'll get this *implicit*
declaration;

   procedure Client_P (Param1 : Client_A;  Param2 : Int.B'Class);

Since Client_A is derived from Int.A, all uses of "A" in the profile
are replaced by Client_A.  But "B" isn't touched.

Note that nothing is inherited when you declare Client_B.  Client_P is
a primitive operation of Int.A but *not* of Int.B (since its parameter
is B'Class, not B).

When you declare an overriding procedure, the procedure has to
override something that is implicitly declared.  The only implicitly
declared procedure is the one I showed above; its second parameter has
type Int.B'Class, not Client_B'Class, and therefore the procedure you
declared can't override it.

The way to do this is to declare your procedure with "Param2 :
Int.B'Class"; then in the body of Client_P, you can say something like

   if Param2 not in Client_B'Class then
      raise <some_exception> with "Wrong client type";
   end if;

                                 -- Adam






  parent reply	other threads:[~2009-02-05 16:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-05 15:05 A problem with "interface" Robert_Matthews
2009-02-05 16:13 ` Jacob Sparre Andersen
2009-02-05 16:14 ` Adam Beneschan [this message]
2009-02-06 14:08   ` Robert_Matthews
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox