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,FREEMAIL_FROM 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!news.eternal-september.org!mx05.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Type vs subtype about visibility of parent's private full definition Date: Wed, 15 May 2013 10:13:00 +0200 Organization: Ada @ Home Message-ID: NNTP-Posting-Host: ll7JxPeHtfBeoFl5nDW1Dg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.15 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:15569 Date: 2013-05-15T10:13:00+02:00 List-Id: Hi all, I already encountered something similar in the past, and it's back again= . = I can only solve it using a subtype instead of a type=E2=80=91new where = I = initially want a type=E2=80=91new, so I'm not happy with using subtype. The case: a child package don't see the full definition of a type from t= he = private part of its parent package when it derives from that type as a = type=E2=80=91new. Below is an example, using a discriminant, which is not required to expo= se = the visibility issue, but which is the reason why I'm not happy to not b= e = able to derive a type=E2=80=91new instead of a subtype: I can't force st= atic=E2=80=91check = as I expected. If the discriminant was not part of the party, I won't = bother. That's the reason why the example makes use of a discriminant an= d = I see the case as an issue. Example: package Parents is pragma Pure; type Discriminant_Type is range 1 .. 5; type Instance_Type (Discriminant : Discriminant_Type) is private; private type Instance_Type (Discriminant : Discriminant_Type) is record Value : Integer; end record; end Parents; package Parents.Childs is pragma Pure; subtype Parent_Type is Parents.Instance_Type; type Instance_Type is new Parent_Type (Discriminant =3D> 2); function Value (Object : Instance_Type) return Integer; private function Value (Object : Instance_Type) return Integer is (Object.Value); -- << Error here end Parents.Childs; I did not check the RM, however I'm blocked if I do this, as GNAT has = complaints with `is (Object.Value)`, and grumbles: no selector "Value" for private type derived from "Instance_Type" I can just work around it, defining `Parents.Childs.Instance_Type` this = = way: subtype Instance_Type is Parent_Type (Discriminant =3D> 2); =E2=80=A6 instead of this way (as was in the above package definition): type Instance_Type is new Parent_Type (Discriminant =3D> 2); I may be naive, I believe `Parents.Childs` private part should see the = full definition of `Parents.Instance_Type` in both case, not only when = deriving a subtype. What are your opinions about this issue? -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity