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!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Can't access record attribute in derived type Date: Wed, 8 Mar 2017 14:08:05 -0600 Organization: JSA Research & Innovation Message-ID: References: <86mvcv4zyu.fsf@gaheris.avalon.lan> NNTP-Posting-Host: rrsoftware.com X-Trace: franka.jacob-sparre.dk 1489003686 25100 24.196.82.226 (8 Mar 2017 20:08:06 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Wed, 8 Mar 2017 20:08:06 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:33495 Date: 2017-03-08T14:08:05-06:00 List-Id: "Mart van de Wege" wrote in message news:86mvcv4zyu.fsf@gaheris.avalon.lan... > Hi, > > I have the following definitions > > private > type Creature is new Base_Creature with record > Attributes : Attribute_Array; > Gender : Possible_Gender := Unknown; > Current_Hit_Points : Integer; > Parents : Group_Of_Creatures.List; > -- An instance of Ada.Containers.Indefinite_Doubly_Linked_Lists > end record; > > In child package #1 (Persons): > > private > type Person is new Creature with record > [...] > and in child package #2 (Knights): > type Knight is new Person with record > [...] > > I try to read the first element of the Parents attribute in knights.adb > like this: > > function Father (K : in Knight) return Knight is > begin > return K.Parents.First_Element; > end Father; > > And the compiler complains: > > "no selector "Parents" for type "Knight" defined" > > What am I missing here? The declarations are private, but shouldn't a > tagged type inherit the entire record of its parent type? That means > that it should have a Parents selector, shouldn't it? I suspect we'll need to see a more complete example to definitively say what the problem is. But if I had to guess, I'd suggest that you've run afoul of the "sibling inheritance problem". The rule for visibility for child components is that *all* of components of the *all* of the ancestors have to be visible at the point of declaration of the child type. If even one of the ancestors is not visible (as happens when deriving from a type defined in a sibling child package), then the components aren't visible, either. Note that in such a case, if you have visiblity on some but not all of the ancestors, you can type convert the object to make them visible. In your example above: return Creature(K).Parents.First_Element; will work if you have some intermediate ancestor without visible components. So, if the above works, you have a sibling inheritance problem, and your choices are either to use conversions like the above, or move the types so that all of the ancestors are visible. Randy.