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,FREEMAIL_FROM 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 cn15mr3395373qab.4.1364610981294; Fri, 29 Mar 2013 19:36:21 -0700 (PDT) X-Received: by 10.50.185.200 with SMTP id fe8mr72355igc.0.1364610981242; Fri, 29 Mar 2013 19:36:21 -0700 (PDT) Path: v17ni6816qad.0!nntp.google.com!ca1no17126273qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 29 Mar 2013 19:36:20 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.20.190.126; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 69.20.190.126 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Interresting, possibly buggy behavior in GNAT generics w/ expression function. From: Shark8 Injection-Date: Sat, 30 Mar 2013 02:36:21 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2013-03-29T19:36:20-07:00 List-Id: On Friday, March 29, 2013 7:04:28 PM UTC-6, Randy Brukardt wrote: > "Simon Wright" 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...