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: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Extending discriminant types References: <20081115101632.5f98c596@cube.tz.axivion.com> In-Reply-To: <20081115101632.5f98c596@cube.tz.axivion.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1226775047 12.201.97.213 (Sat, 15 Nov 2008 18:50:47 GMT) NNTP-Posting-Date: Sat, 15 Nov 2008 18:50:47 GMT Organization: AT&T ASP.att.net Date: Sat, 15 Nov 2008 18:50:47 GMT Xref: g2news2.google.com comp.lang.ada:8417 Date: 2008-11-15T18:50:47+00:00 List-Id: Stefan Bellon wrote: > > 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? If so, is there a way to > achieve what I'm trying, i.e. that I can determine the Kind while > extending and not change it when creating objects? The following does not compile: Var : Child (K => A); You probably don't need the access type that is causing you this confusion. -- Jeff Carter "In the frozen land of Nador they were forced to eat Robin's minstrels, and there was much rejoicing." Monty Python & the Holy Grail 70