comp.lang.ada
 help / color / mirror / Atom feed
From: adam@irvine.com (Adam Beneschan)
Subject: Is this legal? (Language lawyer question)
Date: 15 Aug 2003 20:36:44 -0700
Date: 2003-08-16T03:36:45+00:00	[thread overview]
Message-ID: <b4682ab7.0308151936.5d4f4c73@posting.google.com> (raw)

I've run into some Ada code that is publicly available on the Internet
that doesn't look legal to me.  The rules involved are kind of
complex, so I'd like to make sure I haven't missed something.

The code declares a generic that starts out like this:

generic
   type Item (<>) is abstract tagged private;
   with function "=" (L, R : Item'Class) return Boolean is <>;
   type Item_Ptr is access all Item'Class;
   [etc.]
package Pkg is ...

In the body, there's a construct that looks like this:

package body Pkg is ...

   procedure Proc (Elem : Item'Class) is ...
   begin
      ...
      if ZZZ.all = Elem then ...   -- Ambiguous?

where the type of ZZZ is Item_Ptr.

I can't see how this wouldn't be ambiguous.  Although ZZZ.all and Elem
both have type Item'Class, it appears to me that there are two "="
functions visible at that point:

   function "=" (L, R : Item) return Boolean;
   function "=" (L, R : Item'Class) return Boolean;

where the first one is the predefined operator of the generic formal
type Item (see RM95 12.5(8)), and the second one is the generic formal
function declared above.  Applying 8.6(22-23), the expected type for
the parameters in the first function is Item, and that means that it's
acceptable for the actual parameter to resolve either to Item or
Item'Class.  The consequence is that both of the above functions are
acceptable interpretations for the construct, and thus the construct
should be ambiguous.

So what have I missed?

                                -- thanks, Adam



             reply	other threads:[~2003-08-16  3:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-16  3:36 Adam Beneschan [this message]
2003-08-18 16:37 ` Is this legal? (Language lawyer question) Martin Krischik
2003-08-20 20:50   ` Robert I. Eachus
replies disabled

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