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,8e97b70a5f7d5495 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail NNTP-Posting-Date: Thu, 01 Mar 2007 02:48:44 -0600 From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Brain bug or GNAT bug? References: <87irdlx1ol.fsf@ludovic-brenta.org> Date: Thu, 01 Mar 2007 09:45:35 +0100 Message-ID: <87ejo9wdw0.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:fnUO8/0Q3qzy7C7PfTM4aRyHxpk= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 62.235.211.75 X-Trace: sv3-vfXcTt15F3NmI1IIFS8KFy0TJKjjtWir5six7L1MHn3dOETKbjv4K1q8NsA5/8GOsWPLdbBMpK+aH4B!Dx63qef8zuX1G6V/9Wv7GI+T0GSojPO3dfEZ3+KOZ2GgXg+0iA2koujHidVHHgjMtvrEqztNHQ== X-Complaints-To: abuse@scarlet.be X-DMCA-Complaints-To: abuse@scarlet.biz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.34 Xref: g2news2.google.com comp.lang.ada:9616 Date: 2007-03-01T09:45:35+01:00 List-Id: (see below) writes: > Ludovic Brenta writes: >> Per ARM 3.7(15), the types of DT1.the_size and DT2.the_size must be >> statically compatible. In other words, you must guarantee at compile >> time that "the_size" is in the range of type "modular". Because >> modular's range is not known at compile time but bounded's is, no such >> guarantee exists. >> >> If you remove the "range" constraint on subtype "bounded", then the >> range for "bounded" and the range of "modular" are known at compile >> time to be identical, so all is well. > > But if the declaration of bounded compiles, > the range of bounded must be a subset of the range of modular, The compiler doesn't know that, so inserts run-time checks as aptly illustrated by Jeffrey Carter. > so DT2.the_size must be in the range of modular. > The rule at ARM 3.7(15) seems overly restrictive. The rule implies there must be no run-time checks. I don't think this is overly restrictive, since this is exactly what you want as you explained below. >> What are ou trying to achieve? > > Implement DT2 as a derivation of DT1 with guaranteed bounds on its > size (in the actual s/w, the bounds are also generic parameters, and > DT1 is actually declared in a distinct, with-ed package). Consider that it must be possible to convert explicitly between related types, i.e. from DT1 to DT2 and back. What happens if you want to convert from a DT1 object with unknown bounds to a DT2 with "guaranteed" but different bounds? Remember that generic formal objects are never considered static inside the generic, even if the actuals for some instantiations happen to be static. > At the moment bounds checking for DT2 has to be done by a runtime > check on use of DT2 objects. Yes, but even with your solution, this is still a run-time check, and that's illegal for a discriminant used to constrain a parent type. > I can't help feeling the type system should be able to catch a > misuse, at the point of declaration of a DT2 object, but there does > not seem any way to do that, thanks to ARM 3.7(15). So long as the bounds of DT1 are unknown at compile time, there will be a run-time check somewhere. You can make that implicit or explicit. I think a possible solution is to not declare DT2 as derived from DT1. Make the two types independent, and write a conversion function that takes into account the possible difference in bounds. For example, it would convert a DT1 object with unknown bounds into one *or more* DT2 objects with guaranteed bounds. Actually, make that *zero* or more DT2 objects. -- Ludovic Brenta.