From: dep@swl.msd.ray.com (DONALD PRINCIOTTA)
Subject: Re: Generic Package Visibility Problems! (help)
Organization: Raytheon Company, Tewksbury, MA
Distribution: comp
Date: Sun, 4 Oct 1992 22:10:53 GMT

young@gdfwc3 (Mark Young) writes:


>I am having visibility problems with generic packages.

>Here's an example:

>file #1
>-----------------------------------------------
>generic 

>  Generic_Parameter : Generic_Parameter_Type;

>package Color is

>  type RGB_Type is (RED,GREEN,BLUE);

>  function Get_Color return RGB_Type;

>end Color;
>----------------------------------------------
>file #2
>----------------------------------------------
>with Color;

>package Caller is

>  package C_1 is new Caller( Generic_Argument );

>  procedure Test_Color;

>end Caller;

>package body Caller is 

>  procedure Test_Color is separate;

>end Caller;
>---------------------------------------------
>file #3
>---------------------------------------------
>separate( Caller )

>procedure Test_Color is

>begin

>  if ( C_1.Get_Color = C_1.RED ) then
>	               -------
>	null;

>  end if;

>end Test_Color;
>----------------------------------------------

>This will not work.  For some reason the compiler cannot
>resolve C_1.RED.  It tells me that = is not a legal 
>operation, that C_1.Get_Color returns type RGB_Type but, 
>that it does not understand C_1.RED and that perhaps I 
>needed a "use" clause in the body of Caller.  I don't
>understand this.  My understanding of Ada scoping would
>lead me to believe that this is correct.  Am I missing 
>something?  

>BTW: this is not a complete example, it is only to illustrate
>a point.

>Thanks,

>Mark Young


--- START OF RESPONSE -------------------------------------------------------

Mark,
  The answer to your problem is simple... Just a plain old
everyday visibility problem.  I won't comment of the worth
of your test program, lets just say it could use a little
imagination and leave it at that.... 

The error message displayed by your compile was exactly right...
You don't have an equality operation visible at the point within
your program where you are attempting to invoke the function.

Think on where a types operations are visible??? The operations
are visible where the type is defined (i.e. inside of the 
package in this case.  If you did use the "use clause" it would
solve your visibility problem but that would be the LAMO way to
solve the problem.  You do in have visibility to the "=" operation
the problem stems from the fact that you don't have direct visibility
the the operation.  The following two examples demonstrate 
possible ways to get at your "=" operation.

separate( Caller )
procedure Test_Color is
begin
  if C_1."="(C_1.Get_Color,C_1.RED) then  -- "=" exists within C_1
       null;
  end if;
end Test_Color;

OR --------------------------------



separate( Caller )
procedure Test_Color is
   function "=" ( Left  : in C1.RGB_Type
                  Right : in C1.RGB_Type ) return Boolean renames C_1."=";
   -- Make only the "=" operation directly visible.
   -- This renaming clause could als0 have been placed inside of
   -- the parent routine Caller
begin
  if ( C_1.Get_Color = C_1.RED) then  -- "=" exists within C_1
       null;
  end if;
end Test_Color;


Hope this answers your question .................

                                Don Princiotta
                                dep@swlvx6.msd.ray.com

--- END OF RESPONSE ---------------------------------------------------------