* Resolution of Dispatching Operations
@ 1997-02-23 0:00 Matthew Heaney
1997-02-24 0:00 ` Robert A Duff
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Matthew Heaney @ 1997-02-23 0:00 UTC (permalink / raw)
I have a question about the rules for resolution of (dispatching) operations.
I have a type with 2 operations that differ only with respect to whether
the arguments are class-wide or specific:
procedure Op (L : in T; R : in out T'Class);
procedure Op (L : in T'Class; R : in out T);
If I'm in a context where I have 2 class-wide objects and I call Op, which
version of Op gets called? Like this
declare
O1, O2 : T'Class;
begin
Op (O1, O2);
end;
On my compiler, the first version gets called, but I have no idea why that
one would be favored over the other.
My expectation is that at some point, either at compile-time or at
run-time, I would get an error that says the compiler couldn't figure out
which operation I meant. What am I missing?
Here is the code:
-- STX
package P is
type T is tagged limited null record;
procedure Op (L : in T; R : in out T'Class);
procedure Op (L : in T'Class; R : in out T);
end;
with Ada.Text_IO; use Ada.Text_IO;
package body P is
procedure Op (L : in T; R : in out T'Class) is
begin
Put_Line ("Op T, T'Class");
end;
procedure Op (L : in T'Class; R : in out T) is
begin
Put_Line ("Op T'Class, T");
end;
end;
with P;
procedure test_p is
procedure Q (L : in P.T'Class; R : in out P.T'Class) is
begin
P.Op (L, R);
end;
O1, O2 : P.T;
begin
Q (P.T'Class (O1), P.T'Class (O2));
end;
-- ETX
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Resolution of Dispatching Operations
1997-02-23 0:00 Resolution of Dispatching Operations Matthew Heaney
@ 1997-02-24 0:00 ` Robert A Duff
1997-02-25 0:00 ` Norman H. Cohen
1997-02-26 0:00 ` Tucker Taft
2 siblings, 0 replies; 4+ messages in thread
From: Robert A Duff @ 1997-02-24 0:00 UTC (permalink / raw)
In article <mheaney-ya023680002302970035510001@news.ni.net>,
Matthew Heaney <mheaney@ni.net> wrote:
>procedure Op (L : in T; R : in out T'Class);
>
>procedure Op (L : in T'Class; R : in out T);
>declare
> O1, O2 : T'Class;
>begin
> Op (O1, O2);
This is ambiguous, so you should get a compiler time error.
This really has nothing to do with dispatching -- it's just the
compile-time overload resolution rules that are involved.
IMHO, allowing an ambiguous statement to run, and do who-knows-what, is
a pretty serious compiler bug!
- Bob
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Resolution of Dispatching Operations
1997-02-23 0:00 Resolution of Dispatching Operations Matthew Heaney
1997-02-24 0:00 ` Robert A Duff
@ 1997-02-25 0:00 ` Norman H. Cohen
1997-02-26 0:00 ` Tucker Taft
2 siblings, 0 replies; 4+ messages in thread
From: Norman H. Cohen @ 1997-02-25 0:00 UTC (permalink / raw)
Matthew Heaney wrote:
> I have a type with 2 operations that differ only with respect to whether
> the arguments are class-wide or specific:
>
> procedure Op (L : in T; R : in out T'Class);
>
> procedure Op (L : in T'Class; R : in out T);
>
> If I'm in a context where I have 2 class-wide objects and I call Op, which
> version of Op gets called?
...
> On my compiler, the first version gets called, but I have no idea why that
> one would be favored over the other.
>
> My expectation is that at some point, either at compile-time or at
> run-time, I would get an error that says the compiler couldn't figure out
> which operation I meant. What am I missing?
It looks like a compile-time overloading ambiguity to me. I think what
you're missing is a correct compiler. :-)
--
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Resolution of Dispatching Operations
1997-02-23 0:00 Resolution of Dispatching Operations Matthew Heaney
1997-02-24 0:00 ` Robert A Duff
1997-02-25 0:00 ` Norman H. Cohen
@ 1997-02-26 0:00 ` Tucker Taft
2 siblings, 0 replies; 4+ messages in thread
From: Tucker Taft @ 1997-02-26 0:00 UTC (permalink / raw)
Matthew Heaney (mheaney@ni.net) wrote:
: I have a question about the rules for resolution of (dispatching) operations.
: I have a type with 2 operations that differ only with respect to whether
: the arguments are class-wide or specific:
: procedure Op (L : in T; R : in out T'Class);
: procedure Op (L : in T'Class; R : in out T);
: If I'm in a context where I have 2 class-wide objects and I call Op, which
: version of Op gets called? Like this
: declare
: O1, O2 : T'Class;
: begin
: Op (O1, O2);
: end;
: On my compiler, the first version gets called, but I have no idea why that
: one would be favored over the other.
The compiler has a bug. It should report the call (at compile-time)
as being ambiguous.
: My expectation is that at some point, either at compile-time or at
: run-time, I would get an error that says the compiler couldn't figure out
: which operation I meant. What am I missing?
A bug-free compiler ;-).
: ...
: Matthew Heaney
: Software Development Consultant
: <mailto:matthew_heaney@acm.org>
: (818) 985-1271
-Tucker Taft stt@inmet.com http://www.inmet.com/~stt/
Intermetrics, Inc. Burlington, MA USA
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1997-02-26 0:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-23 0:00 Resolution of Dispatching Operations Matthew Heaney
1997-02-24 0:00 ` Robert A Duff
1997-02-25 0:00 ` Norman H. Cohen
1997-02-26 0:00 ` Tucker Taft
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox