comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Question about name resolution
Date: Tue, 20 Jan 2015 15:39:02 -0500
Date: 2015-01-20T15:39:02-05:00	[thread overview]
Message-ID: <wccegqpb315.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: m9magv$a8e$1@speranza.aioe.org

"Michael B." <michaelb@example.com> writes:

> On 01/20/15 20:00, Jeffrey Carter wrote:
>> There's no way to call the 1st P by the name P. You could rename it and call it
>> by the renamed name.
>
> It works, thank you!
> I found something similar in a library that I want to use.
> I was surprised that this compiles without warnings if neither of the
> procedures is called. Why is such overloading allowed in Ada? It seems
> to make no sense to write a procedure that cannot be called directly.

There is an attempt to forbid overloaded declarations that can never be
called because of ambiguity.  See RM-8.3(26).  It's quite complicated,
and it doesn't really work -- it has both false positives and false
negatives.  Your case is a false negative.

This rule is followed in the Annotated version by 25 paragraphs of
explanatory text!  See AARM-8.3(26.a-26.k).  And several AI's were
needed to fix bugs in this rule.

I challenge you to provide wording that would forbid your case,
and cases like it.  ;-)  A modification or addition to 8.3(26),
I mean.  It's not easy!

I think the rule is a waste of time.  If you have ambiguous calls,
you'll find out at compile time even without that rule, albeit maybe in
some other compilation unit.  Not a big deal.

Here's an example of a false positive:

    package P is
        type A is array (Positive range <>) of Integer;

        function Count(From, Up_To: Integer) return A;
        -- Returns an array from From up to Up_To, so
        -- Count(From => 1, Up_To => 4) returns (1, 2, 3, 4).

        function Count(From, Down_To: Integer) return A; -- Illegal homograph!
        --  E.g. Count(From => 4, Down_To => 1) returns (4, 3, 2, 1).
    end P;

That's illegal, but if it were legal, you could write nonambiguous calls
using named notation.

- Bob


  reply	other threads:[~2015-01-20 20:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-20 18:47 Question about name resolution Michael B.
2015-01-20 19:00 ` Jeffrey Carter
2015-01-20 19:32   ` Michael B.
2015-01-20 20:39     ` Robert A Duff [this message]
2015-01-21 18:25       ` Michael B.
2015-01-21  0:47     ` Jeffrey Carter
2015-01-21 10:54       ` Brian Drummond
2015-01-20 19:43 ` Robert A Duff
replies disabled

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