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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, WEIRD_PORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a3ca673ce44576 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Cannot call primitive op for generic formal derived type: why not? Date: 1999/09/03 Message-ID: <7qodou$loc@hobbes.crc.com>#1/1 X-Deja-AN: 520589876 References: <37cf2237@news1.us.ibm.net> Organization: Coleman Research Corporation X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Newsgroups: comp.lang.ada Date: 1999-09-03T00:00:00+00:00 List-Id: Matthew Heaney 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;