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: border1.nntp.ams3.giganews.com!border2.nntp.ams3.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Variant record limitation - what's a better solution? Date: Wed, 03 Jul 2013 09:23:09 -0700 Organization: Also freenews.netfront.net; news.tornevall.net Message-ID: References: <0606a658-9816-4611-84dd-4f999bf6018e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 3 Jul 2013 16:17:39 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="0ff79f536fa0097e04633d700dc31cb2"; logging-data="11148"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cd7BMXxC9TVISWfHZgGqCT2eZSBO4FN4=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: <0606a658-9816-4611-84dd-4f999bf6018e@googlegroups.com> Cancel-Lock: sha1:PyZF00m7/MI5hYocKo2YSFHlsrA= X-Original-Bytes: 2465 Date: 2013-07-03T09:23:09-07:00 List-Id: On 07/03/2013 12:52 AM, Peter Brooks wrote: > > type > my_object(X : size_type) is > record > name : string(1..80); > case X is > when small => Y : small_type; -- line 20 > when medium => Y : medium_type; -- line 21 > when large => Y: large_type; -- line 22 > end case; > end record; > > The errors are: > line 21 'Y' conflicts with declaration at line 20 > line 22 'Y' conflicts with declaration at line 21 > > I was hoping to have a different type depending on the case, but this doesn't seem allowed. What would achieve this? The problem isn't the types but the component identifiers. Each component name must be unique, even across different variants. So you could do something like type My_Object (Size : Size_ID) is record Name : String (1 .. 80); case Size is when Small => Y_Small : Small_Value; when Medium => Y_Medium : Medium_Value; when Large => Y_Large : Large_Value; end case; end record; -- Jeff Carter "My brain hurts!" Monty Python's Flying Circus 21