comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Doubts on Function Overloading
Date: Mon, 17 Jun 2019 16:15:07 -0700
Date: 2019-06-17T16:15:07-07:00	[thread overview]
Message-ID: <ln36k7n6ro.fsf@kst-u.example.com> (raw)
In-Reply-To: c6d200f3-5582-4947-a381-0dcd20268b9f@googlegroups.com

Ricardo Brandão <rbrandao.br@gmail.com> 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  <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

  reply	other threads:[~2019-06-17 23:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-17 22:31 Doubts on Function Overloading Ricardo Brandão
2019-06-17 23:15 ` Keith Thompson [this message]
2019-06-18  1:03   ` Ricardo Brandão
replies disabled

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