comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Cannot call primitive op for generic formal derived type: why not?
Date: 1999/09/03
Date: 1999-09-03T00:00:00+00:00	[thread overview]
Message-ID: <7qodou$loc@hobbes.crc.com> (raw)
In-Reply-To: 37cf2237@news1.us.ibm.net


Matthew Heaney <matthew_heaney@acm.org> wrote in message
news:37cf2237@news1.us.ibm.net...
> I have a type hierarchy, rooted at P.T, with a private, primitive
operation,
> here called Private_Op.
>
> The root package P has a generic child, P.C, with a generic formal type
that
> derives from T, here called NT.  P.C has a public operation, Op, that
takes
> NT as an access parameter.
>
> The body of P.C.Op tries to call the primitive operation Private_Op.  This
> seems like it should be legal, because NT derives from T, and T has
> Private_Op as a primitive operation (so NT should have inherited it).
>
> Yet my compiler is telling me that the call to Private_Op is illegal:
>
> p-c.adb:5:19: expected type access to "T" defined at p.ads:9
> p-c.adb:5:19: found type access to "Nt" defined at p-c.ads:5
>
> It seems as if the compiler doesn't acknowledge that Private_Op is
primitive
> for NT.
>
> What's up with that?  Is this a compiler bug, or is this program not legal
> Ada?
>
> I thought the whole point of importing a derived type is precisely to be
> able to call the primitive operations for types in that class.  Is this
> expectation incorrect?
>

I'm not that much a language lawyer, but taking the compiler messages at
their word (i.e., that the parameter passed to Private_Op was not of the
expected type), I simply converted to the expected type, and all compiles
with neither error nor warning, viz.:

package body P.C is

   procedure Op (O : access NT) is
   begin
      Private_Op (T (O.all)'access);
   end Op;

end P.C;








      reply	other threads:[~1999-09-03  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-02  0:00 Cannot call primitive op for generic formal derived type: why not? Matthew Heaney
1999-09-03  0:00 ` David C. Hoos, Sr. [this message]
replies disabled

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