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 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1ef593126ef45087,start X-Google-Attributes: gid103376,public From: jsa@alexandria (Jon S Anthony) Subject: Generic children, instances and visibility... Date: 1997/04/09 Message-ID: #1/1 X-Deja-AN: 231759195 Distribution: world Organization: PSI Public Usenet Link Newsgroups: comp.lang.ada Date: 1997-04-09T00:00:00+00:00 List-Id: As we all know, certain visibility issues in Ada can make you scratch your head a bit. Here's one on which I would appreciate any comments. What is the best way of thinking about the case of an instantiation of a generic child package with a constrained generic formal tagged type? In particular, the visibility of the body of the instance to the generic child's parent's private part. Fer'nstance, Say you have a parent library package thus: package P is type T is abstract tagged limited private; ... private type T is abstract tagged limited record F : Some_Type; end record; ... end P; and then you have a generic child package of P, which requires that it's formal be constrained to that of some type derived from T: generic type Nt is new T with private; package P.C is ... end P.C; Does P.C have visibility to the field F of any object of type NT?? At first glance this seems like, "yes, of course - since C is a child of P". So, you might have in the body: package body P.C is ... O : NT; ... O.F := ... -- (**) ... end P.C; And 12.3(11) seems to support this - for the _generic_ unit P.C. OK, but now consider an _instance_ of P.C (which _must_ supply a type derived from P.T): with P.C; package Inst_Holder is type IT is new P.T with null record; package PC_Inst is new P.C(IT); ... end Inst_Holder; Does the body of PC_Inst have access to the field F, i.e., is (**) legal in an instance? 12.3(11) together with 12.3(15) seem to say, "No way - the properties of IT do not include visibility to F (the 15 bit) and this is checked at compile time for the instantiation (the 11 bit)." Well, OK. But now, suppose we make PC_Inst a _child_ of P: with Inst_Types; with P.C; package P.PC_Inst is new P.C(Inst_Types.IT); Now, 12.3(12) would seem to say that in this case, PC_Inst should have visibility to F as it should be equivalent to a simple non generic version and such a version will have access. What's the scoop? /Jon -- Jon Anthony Organon Motives, Inc. Belmont, MA 02178 617.484.3383 jsa@organon.com