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,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,78ec96be17741f16 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Unclear error message - please help Date: 17 Sep 2005 22:32:07 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <432C8690.C37D4AE0@alfred-hilscher.de> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1127010786 32427 192.74.137.71 (18 Sep 2005 02:33:06 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 18 Sep 2005 02:33:06 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:4854 Date: 2005-09-17T22:32:07-04:00 List-Id: Alfred Hilscher writes: > Hello, > > I have a problem with some code I've written. The compiler (GNAT 3.15p > on Windows) reports an error whereas I think it should not. > > > Package spec: > > package Pkg is > procedure Proc (Host : STRING; RC : out Integer; Identifier : in > Integer := 0); > > procedure Proc (Host : STRING; > Time_Response : out Integer; RC : out Integer; > Time_Wait : Integer := 1000; > Identifier : Integer := 0); > end Pkg; > > > Main program: > > with Text_IO; > with Ada.Command_Line; use Ada.Command_Line; > > with Pkg; use Pkg; > > procedure PkgTest is > RC : Integer; > begin > if Argument_Count /= 1 > then > Text_IO.Put_Line ("call: PkgTest "); > return; > end if; > > Proc (Argument (1), RC, 2507); > Text_IO.Put_Line ("RC=" & Integer'Image (RC)); > end PkgTest; > > > The compiler says, that the procedure call is ambigous, but I think, it > is clear, that "Proc" from line 2 should be used, as it has parameters > (in, out, in) while "Proc" from line 4 has (in, out, out). And the value > (2507) in the call of "Proc" can not be used as an "out" parameter. It > this a know error, or do I have strong misunderstandings there? > > pkgtest.adb:15:03: ambiguous expression (cannot resolve "Proc") > pkgtest.adb:15:03: possible interpretation at pkg.ads:4 > pkgtest.adb:15:03: possible interpretation at pkg.ads:2 As others have said, the compiler is correct. I think that's a good thing. The overload resolution rules should not be "too smart" -- they should allow things to be ambiguous (and therefore illegal) if there's a likelihood that the reader of the code will be confused. I think the call "Proc (Argument (1), RC, 2507);" is confusing, because it's hard to know which Proc is called. So it's good that it's illegal. (It's illegal because parameter modes are not taken into account for overload resolution.) It's especially confusing because of all the defaulted parameters. When you have two or more parameters of the same type, named notation is usually a good idea, as somebody suggested. Otherwise, you might make a mistake, and pass RC as the actual parameter for the Time_Response parameter. Other ideas: Don't use Integer all over the place, but instead use different types, to avoid confusion. Or use two different names, instead of calling both "Proc". - Bob