comp.lang.ada
 help / color / mirror / Atom feed
* Generic children, instances and visibility...
@ 1997-04-09  0:00 Jon S Anthony
  1997-04-09  0:00 ` Stephen Leake
  0 siblings, 1 reply; 5+ messages in thread
From: Jon S Anthony @ 1997-04-09  0:00 UTC (permalink / raw)




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





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1997-04-13  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-09  0:00 Generic children, instances and visibility Jon S Anthony
1997-04-09  0:00 ` Stephen Leake
1997-04-09  0:00   ` Jon S Anthony
1997-04-12  0:00     ` Tucker Taft
1997-04-13  0:00     ` Jon S Anthony

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