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!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.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Full view of a private partial view cannot be a subtype Date: Mon, 4 Dec 2017 14:49:52 -0600 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Mon, 4 Dec 2017 20:49:52 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="427"; mail-complaints-to="news@jacob-sparre.dk" 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.7246 Xref: reader02.eternal-september.org comp.lang.ada:49366 Date: 2017-12-04T14:49:52-06:00 List-Id: "Jere" wrote in message news:c6ba70e3-bfd0-42ca-b742-dc472965eea0@googlegroups.com... ... > package New_Type1 is > subtype Instance is Base.Instance; > procedure Operation(Object : in out Instance); > > private > > procedure Operation(Object : in out Instance) renames Base.Operation; > end New_Type1; > > (NOTE: is there a better way to do this?) No, no better way yet, but maybe (large maybe here) in Ada 2020. (I'm leaving out all details because none have been determined yet and perhaps never will be for Ada 2020.) > This is all well and good, but sometimes while I as an implementer > want this kind of relationship, I don't necessarily want to expose > that relationship outside the private section of a package. Here I > run into a problem as I cannot (as far as I can tell) do: > > package New_Type2 is > type Instance is tagged limited private; > procedure Operation(Object : in out Instance); > private > subtype Instance is Base.Instance; This is illegal; a private type has to be completed with a full type, not a subtype. (If you have a compiler that is allowing this, it is confused...) > procedure Operation(Object : in out Instance) renames Base.Operation; ...which makes Instance a different type, and that makes this illegal (if the type declaration is written properly). > end New_Type2; Usually, you're better off allowing the relationship between types to be visible. In that case, this happens automatically. Otherwise, you can usually do this with this a "squirreling" rename (essentially, you have to rename the inherited entity before declaring the new one). However, in this case, you've hidden the inherited operation before you can rename it, so you can't do this. If you wanted a different operation name, it would work: package New_Type3 is type Instance is tagged limited private; procedure Other_Operation(Object : in out Instance); private type Instance is new Base.Instance with record ... end record; procedure Other_Operation(Object : in out Instance) renames Operation; -- (1) end New_Type3; At (1), you are renaming the operation inherited from Base.Instance. That operation isn't visible to clients, only within this package. And it has the correct types. The main use for a "squirrelling" rename is to be able to call the original operation in a overridden operation: package New_Type4 is type Instance is new Base.Instance with record ... end record; -- Operation is inherited here, with the profile: --procedure Operation (Object : in out Instance); private procedure Original_Operation(Object : in out Instance) renames Operation; -- (1) overriding procedure Operation (Object : in out Instance); end New_Type4; The declaration at (1) allows the body of Operation to call the body of Base.Operation (but with the proper types). Randy.