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: a07f3367d7,556e5b18154df788 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.185.79 with SMTP id cn15mr8668225qab.4.1364831889764; Mon, 01 Apr 2013 08:58:09 -0700 (PDT) X-Received: by 10.50.161.225 with SMTP id xv1mr1052023igb.15.1364831889717; Mon, 01 Apr 2013 08:58:09 -0700 (PDT) Path: v17ni6816qad.0!nntp.google.com!ca1no19785012qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 1 Apr 2013 08:58:09 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <65330bfe-39e4-4f7b-85f5-e06e9458bf29@googlegroups.com> Subject: Re: Interresting, possibly buggy behavior in GNAT generics w/ expression function. From: Adam Beneschan Injection-Date: Mon, 01 Apr 2013 15:58:09 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-04-01T08:58:09-07:00 List-Id: On Friday, March 29, 2013 6:04:28 PM UTC-7, Randy Brukardt wrote: > > In Generic_Attribute_Set, you have two Image functions: >=20 > > function Image(Value : Attribute_Values) return String >=20 > > (Attribute_Values is a generic formal scalar) and >=20 > > function Image(Value : Positive) return String >=20 > > and you instantiate the package with Attribute_Values =3D> Integer. >=20 > > What happens when you change the second Image's parameter to Integer is > > that GNAT chooses the wrong Image to call! >=20 > Something is wrong with this description, because as you have described i= t,=20 > any call on Image should be ambiguous and thus illegal. Specifically: >=20 > generic > type Attribute_Values is (<>); > package Test_It is > function Image(Value : Attribute_Values) return String; > function Image(Value : Positive) return String; > end Test_It; >=20 > package A_Test is new Test_It (Integer); >=20 > This instantiation is legal. However, a call like > A_Test.Image (10); > is ambiguous, because there is no possible way to know which routine shou= ld=20 > be called. It's certainly not possible to call the *wrong* one here, beca= use=20 > they are exactly the same for resolution purposes. >=20 > Now, if they have different parameter names: > function Image (Val : Positive) return String; > then > A_Test.Image (Val =3D> 10); -- Should work. > A_Test.Image (10); -- Still ambiguous. >=20 > If GNAT is allowing these calls, *that's* the bug; what happens when you= =20 > change subtypes is irrelevant. >=20 > Perhaps you guys would like to do as you are always griping to others and= =20 > provide a complete enough example to see what you are really talking=20 > about??? Randy, it looks to me that the original code called Image(...) only from in= side the generic specification or body, not outside. =20 I'm sure Randy already knows this, but for the benefit of anyone who doesn'= t: When a call to Image occurs inside the generic spec or body, the meaning= of Image (i.e. which one is selected) depends only on the stuff the compil= er knows when the generic is *compiled*; the actual types used in an *insta= ntiation* don't matter, for this purpose. (Yes, I know things might be a b= it more complicated when dispatching is involved, but that's not an issue h= ere.) For compilers that use "macro expansion" to implement generic instan= tiations (including GNAT, but not Janus/Ada), this poses challenges for the= compiler writer, because it doesn't work to simply replace Attribute_Value= s with Integer when recompiling the generic. This looks like a case that f= ell through the cracks in GNAT. -- Adam