From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Interresting, possibly buggy behavior in GNAT generics w/ expression function.
Date: Fri, 29 Mar 2013 19:36:20 -0700 (PDT)
Date: 2013-03-29T19:36:20-07:00 [thread overview]
Message-ID: <b2d382e6-58c0-42cc-9dd0-0398a98bd537@googlegroups.com> (raw)
In-Reply-To: <kj5dn6$978$1@munin.nbi.dk>
On Friday, March 29, 2013 7:04:28 PM UTC-6, Randy Brukardt wrote:
> "Simon Wright" <simon@pushface.org> wrote in message
>
> news:lysj3eir9b.fsf@pushface.org...
>
> > 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:
Hm, interesting -- I would have thought the other way: that the Image operating on the generic-formal's type would be called only when the value/variable was definitely it's own type rather than possibly its own type.
The To_String function, which calls both image-routines is:
Image(Attr.Value) & -- Certainly the formal variant.
(if Attr.Has_Units then Image(Attr.Unit) -- Certainly the integral version.
else "") -- Certainly a string.
These two calls converge in one case and diverge on the other (when [a] instantiated by Integer, and [b] dependent on the parameter being natural or positive).
Not disagreeing w/ you, just explaining that it seems this shouldn't happen -- and you're assertion that this should be illegal [ambiguity] would indeed prevent it.
> 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.
I see what you're saying.
> 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.
Indeed, that's what's so puzzling. The WHY of it; I could see your explanation above, and see raising an error about it -- but in this case altering the subtype DOES alter behavior -- and it should not because the type of both is exactly the same.
>
> 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???
I thought I had w/ my first post...
next prev parent reply other threads:[~2013-03-30 2:36 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 [this message]
2013-03-30 15:51 ` Simon Wright
2013-04-01 15:58 ` Adam Beneschan
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