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,60fe876e7675f11 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.73.229 with SMTP id o5mr14709177pbv.7.1328637855906; Tue, 07 Feb 2012 10:04:15 -0800 (PST) Path: lh20ni271290pbb.0!nntp.google.com!news2.google.com!postnews.google.com!i18g2000yqf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Weird behavior with modular type Date: Tue, 7 Feb 2012 10:02:40 -0800 (PST) Organization: http://groups.google.com Message-ID: <323fa219-509f-4605-95d9-42573655cf9d@i18g2000yqf.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1328637855 28627 127.0.0.1 (7 Feb 2012 18:04:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 7 Feb 2012 18:04:15 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i18g2000yqf.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-02-07T10:02:40-08:00 List-Id: On Feb 7, 9:24 am, Yannick Duch=EAne (Hibou57) wrote: > > Now, the following, with added "Natural'Pos (...)", did not even compile: > > with Ada.Text_IO; > procedure Bug is > > type Modular_Type is mod 256; > subtype Index_Type is Natural range 1 .. 3; > > E : Modular_Type :=3D 255; > I : Index_Type :=3D 3; > B : Boolean; > > begin > B :=3D E < Natural'Pos (10 ** I); > Ada.Text_IO.Put_Line (Boolean'Image (B)); > end Bug; > > That's counter intuitive. I would expect the first to behave as the > second, with either a failure to compile or range error at run-time. By the way, I don't see any reason this shouldn't compile, although offhand I think it should raise a Constraint_Error at runtime (since 1024 would be the right argument of a function "<" (Left, Right : E) return Boolean and 1024 can't be converted to E without a Constraint_Error). When I compile on GNAT (4.5.2), it says "static expression fails Constraint_Check". This looks like a GNAT bug, though, because there's no static expression. Apparently it thinks it's static because it knows the value of I must still be 3 at that point, but that doesn't make it a static expression according to the language rules, so the program shouldn't be rejected. (Inserting a call to a null nested procedure before the first line of Bug makes the error message go away.) -- Adam