* Cannot call primitive op for generic formal derived type: why not?
@ 1999-09-02 0:00 Matthew Heaney
1999-09-03 0:00 ` David C. Hoos, Sr.
0 siblings, 1 reply; 2+ messages in thread
From: Matthew Heaney @ 1999-09-02 0:00 UTC (permalink / raw)
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?
Thanks in advance,
Matt
--STX
package P is
type T is abstract tagged limited private;
private
type T is abstract tagged limited null record;
procedure Private_Op (O : access T);
end P;
package body P is
procedure Private_Op (O : access T) is
begin
null;
end;
end P;
generic
type NT is new T with private;
package P.C is
procedure Op (O : access NT);
end P.C;
package body P.C is
procedure Op (O : access NT) is
begin
Private_Op (O);
end Op;
end P.C;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Cannot call primitive op for generic formal derived type: why not?
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.
0 siblings, 0 replies; 2+ messages in thread
From: David C. Hoos, Sr. @ 1999-09-03 0:00 UTC (permalink / raw)
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-09-03 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox