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: border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!ottix-news.ottix.net!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Strange error message Date: Mon, 02 Jun 2014 09:49:13 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <33e17033-615d-43d4-8b47-9357c8875a10@googlegroups.com> <17l7hex6vxkj4.wul0z12r7f85.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls7.std.com 1401716946 10633 192.74.137.71 (2 Jun 2014 13:49:06 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 2 Jun 2014 13:49:06 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:dwjoymrtv49BmWrlyA8H7J1+oy0= X-Original-Bytes: 4061 Xref: number.nntp.dca.giganews.com comp.lang.ada:186700 Date: 2014-06-02T09:49:13-04:00 List-Id: "Dmitry A. Kazakov" writes: > The first objection is that the legality of inheriting Create in > > type Base is tagged private; > function Create return Base; > > type High is new Base with private; > > depends on the private part of the package. This is not good. Privacy breakage is not good, but there is no privacy breakage here. Privacy breakage happens when the legality of clients depends on the contents of the private part. Here, the legality of the package itself depends on the contents of the private part (which is always the case!). Clients can only see the visible part as quoted above. The private part could be: private type Base is tagged null record; type High is new Base with null record; or: private type Base is tagged null record; type High is new Base with record H_Val : Natural; end record; overriding function Create return High is (Base'(Create) with H_Val => <>); both of which are legal. The visible part promises that there will be a function Create returning High. The first private part above accomplishes that by using the one implicitly generated by the compiler, which looks like this: function Create return High is (Base'(Create) with null record); If you wrote it by hand (as you were required to do in Ada 95), you would almost certainly write something equivalent. What else could it reasonably do? The compiler can't automatically create Create in the second case, because it doesn't know what value you want for H_Val. > The second objection is, if the above is not good then > > type High is new Base with null record; > > should make no difference. Well, since your first objection is invalid, the premise of your second objection is false. ;-) > --------------- > Of course one could argue in favor of the rule that all primitive > operations are in some sense overridden anyway. It is only the way the > bodies are constructed (inherited vs. provided by the user), what makes > difference. I.e. whether > > overriding function Create return High; > > appears in the public part of the package or not, that is an implementation > detail uninteresting to the clients. I would agree with that, but it is not > how the language is designed presently. Not sure what you mean. You can put the above "overriding..." in the visible part or the private part, or (in the null record case) leave it out. It makes no difference to clients. > It is, as always, too late, but probably overriding (with new body) were to > appear strictly in the package body. Yes, that would make sense. I suggested that during Ada 9X. The reasons not to do that have to do with making compilers easier to write. In fact, private parts should not exist; that stuff belongs in the body. >...Then the rule of null extension would > be all OK to me. Is it OK with you now, having read my comments above? - Bob