comp.lang.ada
 help / color / mirror / Atom feed
* Is this legal? (Language lawyer question)
@ 2003-08-16  3:36 Adam Beneschan
  2003-08-18 16:37 ` Martin Krischik
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Beneschan @ 2003-08-16  3:36 UTC (permalink / 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



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

* Re: Is this legal? (Language lawyer question)
  2003-08-16  3:36 Is this legal? (Language lawyer question) Adam Beneschan
@ 2003-08-18 16:37 ` Martin Krischik
  2003-08-20 20:50   ` Robert I. Eachus
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Krischik @ 2003-08-18 16:37 UTC (permalink / raw)


Adam Beneschan wrote:

> 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.

Intersting. Well it does compile and the programs based on it are running
fine. Still if I had made a fundamental mistake here I would like to know
about it.

With regards

Martin.

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




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

* Re: Is this legal? (Language lawyer question)
  2003-08-18 16:37 ` Martin Krischik
@ 2003-08-20 20:50   ` Robert I. Eachus
  0 siblings, 0 replies; 3+ messages in thread
From: Robert I. Eachus @ 2003-08-20 20:50 UTC (permalink / raw)


Martin Krischik wrote:
> Adam Beneschan wrote:
> 
> 
>>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.
> 
> 
> Intersting. Well it does compile and the programs based on it are running
> fine. Still if I had made a fundamental mistake here I would like to know
> about it.
> 
> With regards
> 
> Martin.
> 

Please forward the actual example to ada-comment@ada-auth.org.  I've 
looked at it, and I think that "we all know" what is meant, but that 
isn't what the standard says...

-- 
                                               Robert I. Eachus

"As far as I'm concerned, war always means failure." -- Jacques Chirac, 
President of France
"As far as France is concerned, you're right." -- Rush Limbaugh




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

end of thread, other threads:[~2003-08-20 20:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-16  3:36 Is this legal? (Language lawyer question) Adam Beneschan
2003-08-18 16:37 ` Martin Krischik
2003-08-20 20:50   ` Robert I. Eachus

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