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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Generic parent accessing his child? Date: Sat, 06 Dec 2014 07:49:41 +0000 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="d7244c06a78575e4dbdf34623acd89dd"; logging-data="4362"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/C/Jp86JG7ciEhbG3SDzxlZmcm62FzLbg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:PW1WBtYr2GBKpUKj4Fi1Iykv+SA= sha1:i2dwEkXYlbG5micMG02dPDGpK9g= Xref: news.eternal-september.org comp.lang.ada:23895 Date: 2014-12-06T07:49:41+00:00 List-Id: hreba writes: > Without generics I had no problem letting a parent access his child, a > "with" was enough. With generics I have the following problem: > > ------------------------------------------------------- > > generic -- a package used as generics parameter > package T is > type Ttype is private; > procedure Init (t: in out Ttype); > private > type Ttype is new Integer; > end T; > > package body T is > procedure Init (t: in out Ttype) is > begin > t:= 0; > end Init; > end T; > > -------------------------------------------------------- > > with T; -- the parent > generic > with package U is new T(<>); > package P is > type AD is abstract tagged null record; > type A is access all AD'Class; > function NewA return A; > end P; > > with P.Q; > package body P is > function NewA return A is > begin > return A(P.Q.NewB); -- <-- ERROR > end NewA; > end P; > ------------------------------------------------------- > > generic -- the child > package P.Q is > type BD is new AD with > record > i: U.Ttype; > end record; > type B is access all BD; > function NewB return B; > end P.Q; > > package body P.Q is > function NewB return B is > b0: B; > begin > b0:= new BD; > U.Init(b0.i); > return b0; > end NewB; > end P.Q; > > ----------------------------------------------------- > > The error message refers to the line marked above and reads: > > Invalid prefix in selected component "Q". > > What would be the correct way? Compiled with -gnatwa (enables many additional warnings) gives 22. with P.Q; | >>> warning: unit "P.Q" is never instantiated 23. package body P is 24. function NewA return A is 25. begin 26. return A(P.Q.NewB); | >>> invalid prefix in selected component "P.Q" 27. end NewA; 28. end P; because P.Q is itself generic. You can get the code to compile by with P.Q; package body P is package My_Q is new P.Q; function NewA return A is begin return A(My_Q.NewB); end NewA; end P; if that does what you want.