comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Object.Operation and child package
Date: Wed, 25 Jun 2008 12:03:24 -0700 (PDT)
Date: 2008-06-25T12:03:24-07:00	[thread overview]
Message-ID: <a1f91f7f-ec2e-4e25-89c7-f069845779e0@s21g2000prm.googlegroups.com> (raw)
In-Reply-To: 87vdzx9x3n.fsf@ludovic-brenta.org

On Jun 25, 11:40 am, Ludovic Brenta <ludo...@ludovic-brenta.org>
wrote:
> pascal.mala...@gmail.com writes:
> > Hi Ada05 experts,
>
> > Is it normal to reject compilation of Object.Operation notation when
> > operation is in a child package:
>
> > package Pack is
> >   type Typ is tagged null record;
> >   procedure Proc1 (Var : in Typ);
> > end Pack;
>
> > package Pack.Sub is
> >   procedure Proc2 (Var : in Typ);
> > end Pack.Sub;
>
> > with Pack.Sub;
> > procedure Proc is
> >   Obj : Pack.Typ;
> > begin
> >   Obj.Proc1;
> >   Obj.Proc2;
> > end Proc;
>
> > The second call does not compile (with gnat):
> > proc.adb:6:04: no selector "Proc2" for type "Typ" defined at pack.ads:
> > 3
>
> Yes, this is normal because Proc2 is not a primitive operation of Typ
> (or, in other words, it is not a method of Typ).  A primitive
> operation, by definition, is declared in the same package as its type.

"Primitive operation" is the wrong concept here.  First of all, the
subprogram only has to be declared in the same declarative region as
the type, or an ancestor of the type.  The "same declarative region"
can be in a procedure body or package body, which makes them not
primitive operations since primitive operations have to be in a
package specfication.  Also, the subprogram can be a subprogram whose
first parameter is Typ'Class; those are not primitive operations of
Typ, but they can be used in Object.Operation notation.  Finally, a
subprogram can be a primitive operation of Typ even if its second
parameter (or third, etc.) has the right type, or if it's a function
that returns Typ; but it can't be used in Object.Operation notation
unless the *first* parameter has the right type.

But in this case, yes, since Proc2 isn't declared in the same package
as Typ, it can't be used.

                                  -- Adam




  reply	other threads:[~2008-06-25 19:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-25 17:41 Object.Operation and child package pascal.malaise
2008-06-25 18:40 ` Ludovic Brenta
2008-06-25 19:03   ` Adam Beneschan [this message]
2008-06-26  5:56     ` pascal.malaise
2008-06-25 18:51 ` Jeffrey R. Carter
replies disabled

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