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.2 required=5.0 tests=BAYES_00,URI_TRY_3LD, WEIRD_PORT autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Doubts on Function Overloading Date: Mon, 17 Jun 2019 16:15:07 -0700 Organization: None to speak of Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="cc9714341667cff30033f29bcd1d0b9f"; logging-data="23057"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/HSY4To27IJXHrqdNacalt" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:LrazpZi6kDRNfuC/8APOmOf9vPE= sha1:sFMmLBlg6v/2JLYZIWMHEWet6b4= Xref: reader01.eternal-september.org comp.lang.ada:56669 Date: 2019-06-17T16:15:07-07:00 List-Id: Ricardo Brandão writes: > In the very first program I tried after finish the tutorial from > Learn.Adacore.com I got some compile errors related to Overloading. > > My idea was verify how Ada deal with JSON. So, I found out this > program [1]. > > I created a project on GPS, included GnatCool as dependence, and when > I tried to compile, I got the error: > > λ gprbuild.exe main.adb > using project file adajson.gpr > Compile > [Ada] main.adb > main.adb:16:11: ambiguous call to "Set_Field" > main.adb:16:11: possible interpretation at gnatcoll-json.ads:317 > main.adb:16:11: possible interpretation at gnatcoll-json.ads:323 > main.adb:30:11: ambiguous call to "Set_Field" > main.adb:30:11: possible interpretation at gnatcoll-json.ads:317 > main.adb:30:11: possible interpretation at gnatcoll-json.ads:323 > gprbuild: *** compilation phase failed > > The source code is: > > 13 Penguin.Set_Field (Field_Name => "name", > 14 Field => "Linux"); > 15 > 16 Penguin.Set_Field (Field_Name => "born", > 17 Field => 1992); > > > 28 Penguin := Read (JSON_String, "json.errors"); > 29 > 30 Penguin.Set_Field (Field_Name => "born", > 31 Field => 1986); > > The source code of gnatcool-json.ads cited on error: > > 317 procedure Set_Field > 318 (Val : JSON_Value; > 319 Field_Name : UTF8_String; > 320 Field : Integer) > 321 with Pre => Val.Kind = JSON_Object_Type; > 322 > 323 procedure Set_Field > 324 (Val : JSON_Value; > 325 Field_Name : UTF8_String; > 326 Field : Long_Integer) > 327 with Pre => Val.Kind = JSON_Object_Type; > > > If I changed 1992 to "1992" on line 16, and 1986 to "1986" on line 30, the program compile ok. I presume there's an overload of Set_Field that has Field as a String (or UTF8_String). > Why compile didn't resolve correctly, as stated here [2]? Because the literal 1992 doesn't distinguish between Integer and Long_Integer. Integer literals are of type *universal_integer*, which can be implicitly converted to any integer type. (The asterisks denote italics; the name "universal_integer" is not visible.) Try this: Penguin.Set_Field (Field_Name => "born", Field => Integer'(1992)); so the argument is visibly of type Integer, not univeral_integer. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */