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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a1bd0c210a306408 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-19 22:31:45 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc54.POSTED!not-for-mail Message-ID: <3EF29C10.7080807@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: discriminants and derived types Q References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.62.164.137 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc54 1056087100 24.62.164.137 (Fri, 20 Jun 2003 05:31:40 GMT) NNTP-Posting-Date: Fri, 20 Jun 2003 05:31:40 GMT Organization: AT&T Broadband Date: Fri, 20 Jun 2003 05:31:40 GMT Xref: archiver1.google.com comp.lang.ada:39477 Date: 2003-06-20T05:31:40+00:00 List-Id: tmoran@acm.org wrote: > I have two compilers that accept this package spec, and one that complains > about child3, though it accepts child1 and child2. Who's right and why? GNAT is right. RM 3.7.1(7) says: A discriminant_constraint is only allowed in a subtype_indication whose subtype_mark denotes either an unconstrained discriminated subtype, or an unconstrained access subtype whose designated subtype is an unconstrained discriminated subtype. This paragraph was extended by 8652/0008 (AI95-168) but that added sentence only has to do with access discriminants. But you forgot the most important question, how should you fix it? Remove the discrimint constraint in the visible part of the package. It only duplicates the constraint in the private part: package testsd is type parent1(a,b:integer) is record null;end record; type child1(b:integer) is new parent1(a=>1,b=>b); type parent2(a,b:integer) is tagged null record; type child2(b:integer) is new parent2(a=>1,b=>b) with null record; type parent3(a,b:integer) is tagged null record; type child3(b:integer) is new parent3 with private; private type child3(b:integer) is new parent3(a=>1,b=>b) with null record; end testsd; If it bothers you that you can't have the discriminant constraint public and the record extension private, it is a safety issue. Allowing non-static discriminants to appear in two different scopes can cause "interesting" problems. The overload resolution as such is not a problem, but the expressions involved could evaluate differently in the different scopes, even though they appear identical at compile time. So the rule says you can't different discriminant constraints for different views of a type. The alternative would be to have the compiler prove that the constraints are identical and reject them otherwise. Not worth the agony. Note that the workings of the rule in this case are a bit funny. It would seem that the public view of the type is unconstrained. But because the record extension is private, you can only assign to the object as a whole in the private part, the body, or other places where the private view is visible. But in all these places, the type is constrained, so assignment can never change the discriminants.