comp.lang.ada
 help / color / mirror / Atom feed
* Ambiguity detected - Why?
@ 1996-06-05  0:00 Alan Paterson
  1996-06-06  0:00 ` Adam Beneschan
  1996-06-06  0:00 ` Robert A Duff
  0 siblings, 2 replies; 3+ messages in thread
From: Alan Paterson @ 1996-06-05  0:00 UTC (permalink / raw)



The following results when compiling using DECAda/VMS. We cannot understand why 
the compiler finds the marked call ambiguous. Can anyone explain it?

      1 procedure AMBIGUITY_TEST is
      2 --
      3    type T_ENUM is (A, B, C);
      4 --
      5    type T_ENUM_ARR is array(POSITIVE range <>) of T_ENUM;
      6 --
      7 -- 
-----------------------------------------------------------------------------
      8    procedure PROC(
      9                 PARA : in STRING) is
     10    begin
     11       null;
     12    end PROC;
     13 -- 
-----------------------------------------------------------------------------
     14    procedure PROC(
     15                 PARA : in T_ENUM_ARR) is
     16    begin
     17       null;
     18    end PROC;
     19 -- 
-----------------------------------------------------------------------------
     20 --
     21 begin
     22    PROC((A, B));
...............1
%ADAC-E-AMBIGRSL, (1) Ambiguity detected during overload resolution [LRM 8.7]
%ADAC-I-SUPPMEAN, (1) For procedure call PROC the meanings considered are
            call of procedure body PROC (STRING) declared at line 8
            call of procedure body PROC (T_ENUM_ARR) declared at line 14
        For array aggregate the result type is any non-limited array or record 
type

     23    PROC("(A, B)");
     24    PROC(T_ENUM_ARR'(A, B));
     25 end AMBIGUITY_TEST;


-- 
Alan Paterson
Berne, Switzerland




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Ambiguity detected - Why?
  1996-06-05  0:00 Ambiguity detected - Why? Alan Paterson
  1996-06-06  0:00 ` Adam Beneschan
@ 1996-06-06  0:00 ` Robert A Duff
  1 sibling, 0 replies; 3+ messages in thread
From: Robert A Duff @ 1996-06-06  0:00 UTC (permalink / raw)



In article <31B590D2.4193@dial.eunet.ch>,
Alan Paterson  <paterson@dial.eunet.ch> wrote:
>The following results when compiling using DECAda/VMS. We cannot understand why 
>the compiler finds the marked call ambiguous. Can anyone explain it?

>     22    PROC((A, B));
>...............1
>%ADAC-E-AMBIGRSL, (1) Ambiguity detected during overload resolution [LRM 8.7]

The type of an aggregate must be determined by the surrounding context.
The compiler is not allowed to look inside the aggregate in order to
determine its type.  In Ada 95, this is 4.3(3).  There's an equivalent
rule in Ada 83, worded differently.  The compiler thinks, OK I've got an
aggregate, so it must be of some composite type, but I don't know which
composite type, since I'm not allowed to look inside the aggregate.  But
I've got two different things called PROC, which both take a parameter
of a composite type, so I've got an ambiguity.

No big deal -- just use a qualified expression to tell the compiler what
type you meant.

- Bob




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Ambiguity detected - Why?
  1996-06-05  0:00 Ambiguity detected - Why? Alan Paterson
@ 1996-06-06  0:00 ` Adam Beneschan
  1996-06-06  0:00 ` Robert A Duff
  1 sibling, 0 replies; 3+ messages in thread
From: Adam Beneschan @ 1996-06-06  0:00 UTC (permalink / raw)



Alan Paterson <paterson@dial.eunet.ch> writes:
 >The following results when compiling using DECAda/VMS. We cannot understand why 
 >the compiler finds the marked call ambiguous. Can anyone explain it?
 >
 >      1 procedure AMBIGUITY_TEST is
 >      2 --
 >      3    type T_ENUM is (A, B, C);
 >      4 --
 >      5    type T_ENUM_ARR is array(POSITIVE range <>) of T_ENUM;
 >      6 --
 >      7 -- 
 >-----------------------------------------------------------------------------
 >      8    procedure PROC(
 >      9                 PARA : in STRING) is
 >     10    begin
 >     11       null;
 >     12    end PROC;
 >     13 -- 
 >-----------------------------------------------------------------------------
 >     14    procedure PROC(
 >     15                 PARA : in T_ENUM_ARR) is
 >     16    begin
 >     17       null;
 >     18    end PROC;
 >     19 -- 
 >-----------------------------------------------------------------------------
 >     20 --
 >     21 begin
 >     22    PROC((A, B));
 >...............1
 >%ADAC-E-AMBIGRSL, (1) Ambiguity detected during overload resolution [LRM 8.7]
 >%ADAC-I-SUPPMEAN, (1) For procedure call PROC the meanings considered are
 >            call of procedure body PROC (STRING) declared at line 8
 >            call of procedure body PROC (T_ENUM_ARR) declared at line 14
 >        For array aggregate the result type is any non-limited array or record 
 >type
 >
 >     23    PROC("(A, B)");
 >     24    PROC(T_ENUM_ARR'(A, B));
 >     25 end AMBIGUITY_TEST;

8.7(12) explains this: "The rules that require the type of an
aggregate or string literal to be determinable solely from the
enclosing complete context...".

This isn't an easy statement to understand.  But basically, it means
that when the compiler is trying to figure out which overloaded
subprogram is trying to use, if it sees that the parameter is an
aggregate, it doesn't have to look at the whole aggregate to figure
out what type it is.  All it has to do is say, "This is an aggregate."
So when it sees (A,B) in your example, it starts looking for a
declaration of PROC that takes any composite type (i.e. array or
record) as a parameter.  Since both of your declarations take array
types as parameters, the call to PROC is considered ambiguous.

I hope my explanation helps.  IMHO, this isn't one of the easier Ada
rules to understand.  If you really don't want to change the name of
one of your PROC's, the form you used on line 24 will work fine.

                                -- Adam




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1996-06-06  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-05  0:00 Ambiguity detected - Why? Alan Paterson
1996-06-06  0:00 ` Adam Beneschan
1996-06-06  0:00 ` Robert A Duff

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