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,9b7d3a51d0d8b6ee X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!l33g2000pri.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Extending discriminant types Date: Mon, 17 Nov 2008 08:30:45 -0800 (PST) Organization: http://groups.google.com Message-ID: <166efe91-849b-46f6-98d2-cb2c0991c6b8@l33g2000pri.googlegroups.com> References: <20081115101632.5f98c596@cube.tz.axivion.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1226939446 17962 127.0.0.1 (17 Nov 2008 16:30:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 17 Nov 2008 16:30:46 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l33g2000pri.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ 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) Xref: g2news1.google.com comp.lang.ada:2695 Date: 2008-11-17T08:30:45-08:00 List-Id: On Nov 15, 1:16 am, Stefan Bellon wrote: > Hi, > > I stumbled across some behaviour when extending an unconstrained > discriminant type while providing the constraint when extending. Assume > the following code: > > type Kind is (A, B); > > type Base (K : Kind) is abstract tagged record > case K is > when A => null; > when B => Dummy : Natural; > end case; > end record; > > type Base_Access is access all Base'Class; > > type Child is new Base (B) with null record; > > In this case I would have thought that type Child is now constrained to > Kind B and no object of type Child with Kind A can be created. > > However, the following compiles (with GNAT) and does not throw an > exception at runtime: > > Var : Base_Access := new Child'(K => A); > > Am I misunderstanding the Ada semantics? No, I think GNAT is wrong here. The semantics of allocators is that an object is created with K=A, and then it tries to convert this object to the subtype Child, but since Child has a constraint and the object violates that constraint, a Constraint_Error should be raised. However, I think this would be OK and would not raise an exception: Var : Base_Access := new Child'Base' (K => A); since there are no constraints to violate. I'm not 100% sure I'm right about this, though. -- Adam