Question on visibility of inherited operations 
Author Message
 Question on visibility of inherited operations


I stumbled onto an interesting example of inconsistent treatment of
the  visibility  of  inherited operations by various compilers.  In
discussing this with several of my co-workers, we are divided as to
whether the following code should compile with or without error.

Consider the following:


   TYPE Foo IS NEW Integer;

END Package1;

WITH Package1;

   SUBTYPE Bar is Package1.Foo RANGE 1..10;

END Package2;

WITH Package2;

   FUNCTION "+" (Left, Right: Package2.Bar) RETURN Package2.Bar
                RENAMES Package2."+";
------------------------^A                                                   ###
---------------------------------^B                                          ###
--### A:error: RM 8.5(7): cannot resolve to subprogram with this profile
--### B:error: RM 4.1.3: selector undefined

END Main;

This  program compiles  successfully  under Alsys and  Telesoft.  It
fails under  both DEC  Ada and  Verdix (SunAda).  The Verdix(SunAda)
error message is shown embedded in the code example above.  The  DEC
Ada error message was similar:

                RENAMES Package2."+";
%ADAC-E-NOSELECTED1, (1) No selected component named + is defined for
                         package specification Package2 ...

In looking at the code, I am really surprised that Alsys and Telesoft
allow this program to compile.  Since I got 50-50 results  I suspect
the LRM provides no  guidance as to whether this  program should  be
rejected...Or am I mistaken?

Successful compilation of this program implies  that there is a  "+"
operator  visible  on objects  of base type  Package1.Foo  that  are
declared in Package2.  Of course, as it stands this  isn't true,  so
how can this be allowed to compile?

Obviously, the workaround is to use the "USE" clause, or  to perform
a renaming of the "+" operator defined  in Package1, and  place  the
rename definition in Package2.  But I'm  more interested  in knowing
why some compilers reject this and others let it compile.

Any thoughts on this subject?  Anyone have any other compilers you'd
like to try this example on?  Apologies  if this  topic has come  up

Dennis Gibbs
TRW Systems Integration Group
Chantilly, VA
(703) 802-1961

Dennis Gibbs

Mon, 08 Aug 1994 20:52:27 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Q on visibility and re-exporting of inherited ops

2. Visibility for operations of formal private extensions

3. Q on Visibility of Controlled Type Operations

4. Inheriting controlled operations in the private part

5. Relational operations on discrete types / visibility

6. a visibility question

7. question about overloading rules, homographs and visibility

8. Operator visibility question

9. Ada 95 visibility question

10. Question on Signal visibility ?

11. Fixed point operator visibility question

12. Ada 9x type visibility question


Powered by phpBB® Forum Software