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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f93e461e8491e322 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!51g2000cwl.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Limited_Controlled, orthogonality and related issues Date: 18 Jan 2007 09:02:24 -0800 Organization: http://groups.google.com Message-ID: <1169139744.717060.69070@51g2000cwl.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1169139750 11574 127.0.0.1 (18 Jan 2007 17:02:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 18 Jan 2007 17:02:30 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: 51g2000cwl.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:8269 Date: 2007-01-18T09:02:24-08:00 List-Id: Maciej Sobczak wrote: > Hi, > > Consider the following problem: > > package P is > type T is limited private; > type S is limited private; > procedure Do_The_Job(X : in T; Y : in S); > -- and gazillion of other subprograms like Do_The_Job > private > -- ... > end P; > > At some point I decide to add automatic destruction to T and S, so the > package becomes: > > with Ada.Finalization; > package P is > type T is limited private; > type S is limited private; > procedure Do_The_Job(X : in T; Y : in S); > -- and gazillion of other subprograms like Do_The_Job > private > type T is new Ada.Finalization.Limited_Controlled with -- ... > type S is new Ada.Finalization.Limited_Controlled with -- ... > end P; > > Suddenly, the package no longer compiles: > > "operation can be dispatching in only one type" > > By making T and S controlled types, they became tagged and Do_The_Job is > now incorrect. On looking at this, I wonder if this was an error in the design of Ada 95. Primitive operations of tagged types are dispatching, and the reason is that so that another package can declare a type extension from a tagged type and inherit the dispatching operation, and possibly override it, and then somebody could use the operation on a class-wide type to call the correct operation for that particular object, and thus achieve polymorphism. But when the partial view of a type is not tagged, then other packages can't derive type extensions from it and can't apply 'Class to it, so was there any logical reason why an operation on that type (declared in the visible part of the package) should be dispatching? Maybe not, since the dispatch could "almost never" take place in practice, and since making the operation dispatching adds restrictions just like the one Maciej found. I say "almost never" because in theory, since the private part or body of P or of a child of P (or the visible part of a private child of P) *could* derive a type extension from the tagged type and dispatch. But I'd guess that such usage would be rare. So it seems to me that (1) it would have been better to say in 3.9.2 that a primitive operation of an untagged private type whose full view is tagged is not dispatching, at least if the operation is declared in the visible part of the package; or (2) some way should have been provided for the programmer to specify that an operation that 3.9.2 defines as "dispatching" really isn't. Maybe (2) is still possible. I'm guessing that it's way too late to make (1) the rule. So this is probably really just a useless rant. Has this issue been discussed somewhere else, by the way? -- Adam