On Friday, March 29, 2013 7:04:28 PM UTC-6, Randy Brukardt wrote:
> "Simon Wright" <
si...@pushface.org> wrote in message
>
> news:lysj3ei...@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...