comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Interresting, possibly buggy behavior in GNAT generics w/ expression function.
Date: Mon, 1 Apr 2013 08:58:09 -0700 (PDT)
Date: 2013-04-01T08:58:09-07:00	[thread overview]
Message-ID: <65330bfe-39e4-4f7b-85f5-e06e9458bf29@googlegroups.com> (raw)
In-Reply-To: <kj5dn6$978$1@munin.nbi.dk>

On Friday, March 29, 2013 6:04:28 PM UTC-7, Randy Brukardt wrote:

> > In Generic_Attribute_Set, you have two Image functions:
> 
> >    function Image(Value : Attribute_Values) return String
> 
> > (Attribute_Values is a generic formal scalar) and
> 
> >    function Image(Value : Positive) return String
> 
> > and you instantiate the package with Attribute_Values => Integer.
> 
> > What happens when you change the second Image's parameter to Integer is
> > that GNAT chooses the wrong Image to call!
> 
> Something is wrong with this description, because as you have described it, 
> any call on Image should be ambiguous and thus illegal. Specifically:
> 
>     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;
> 
>    package A_Test is new Test_It (Integer);
> 
> This instantiation is legal. However, a call like
>     A_Test.Image (10);
> is ambiguous, because there is no possible way to know which routine should 
> be called. It's certainly not possible to call the *wrong* one here, because 
> they are exactly the same for resolution purposes.
> 
> Now, if they have different parameter names:
>     function Image (Val : Positive) return String;
> then
>    A_Test.Image (Val => 10); -- Should work.
>    A_Test.Image (10); -- Still ambiguous.
> 
> If GNAT is allowing these calls, *that's* the bug; what happens when you 
> change subtypes is irrelevant.
> 
> Perhaps you guys would like to do as you are always griping to others and 
> provide a complete enough example to see what you are really talking 
> about???

Randy, it looks to me that the original code called Image(...) only from inside the generic specification or body, not outside.  

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 compiler knows when the generic is *compiled*; the actual types used in an *instantiation* don't matter, for this purpose.  (Yes, I know things might be a bit more complicated when dispatching is involved, but that's not an issue here.)  For compilers that use "macro expansion" to implement generic instantiations (including GNAT, but not Janus/Ada), this poses challenges for the compiler writer, because it doesn't work to simply replace Attribute_Values with Integer when recompiling the generic.  This looks like a case that fell through the cracks in GNAT.

                                  -- Adam



  parent reply	other threads:[~2013-04-01 15:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 17:34 Interresting, possibly buggy behavior in GNAT generics w/ expression function Shark8
2013-03-28 18:06 ` Simon Wright
2013-03-28 18:38   ` Shark8
2013-03-30  5:59     ` Stephen Leake
2013-03-30 14:20       ` Shark8
2013-03-29  7:45 ` Simon Wright
2013-03-29 12:27   ` Dmitry A. Kazakov
2013-03-29 14:45     ` Simon Wright
2013-03-29 16:21       ` Dmitry A. Kazakov
2013-03-29 16:43         ` Shark8
2013-03-29 17:43         ` Eryndlia Mavourneen
2013-03-29 17:45           ` Eryndlia Mavourneen
2013-03-29 18:38             ` Simon Wright
2013-03-30  0:56         ` Randy Brukardt
2013-03-30  9:24           ` Dmitry A. Kazakov
2013-04-02  0:52             ` Randy Brukardt
2013-04-02  8:51               ` Dmitry A. Kazakov
2013-04-02 21:59                 ` Randy Brukardt
2013-03-29 14:47   ` Shark8
2013-03-29 14:56     ` Shark8
2013-03-30  1:04   ` Randy Brukardt
2013-03-30  2:36     ` Shark8
2013-03-30 15:51     ` Simon Wright
2013-04-01 15:58     ` Adam Beneschan [this message]
2013-04-02  0:46       ` Randy Brukardt
2013-04-02  8:18         ` Simon Wright
2013-04-02 11:14         ` Stephen Leake
2013-04-02 22:00           ` Randy Brukardt
2013-04-02 23:01             ` Adam Beneschan
2013-04-04  0:08               ` Randy Brukardt
2013-03-29 14:47 ` Simon Wright
2013-03-29 14:54   ` Shark8
2013-03-29 15:26     ` Bill Findlay
2013-03-29 15:48     ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox