From: Andrea Taverna on
Hello everyone,

I have the following packages:


generic
with package P is new Q (<>);
use P;
package Parent is
....
end Parent;

generic
Parent.Child is
....
end Parent.Child;


I can see P declarations inside Parent, but in Child I need to prefix
everything with 'P.', even if I add a use-clause.
This happens with gnat-4.3.0 .
Is it normal? How can I "use" P inside Child?

thanks

Andrea
From: Georg Bauhaus on
Andrea Taverna schrieb:

> generic
> with package P is new Q (<>);
> use P;
> package Parent is
> ...
> end Parent;
>
> generic
> Parent.Child is
> ...
> end Parent.Child;
>
>
> I can see P declarations inside Parent, but in Child I need to prefix
> everything with 'P.', even if I add a use-clause.
> This happens with gnat-4.3.0 .
> Is it normal? How can I "use" P inside Child?

generic
Parent.Child is
use P;
end Parent.Child;

From: Andrea Taverna on
On 15 Dic, 22:00, Georg Bauhaus <rm.dash-bauh...(a)futureapps.de> wrote:
> Andrea Taverna schrieb:
>
>
>
> > generic
> >    with package P is new Q (<>);
> >    use P;
> > package Parent is
> > ...
> > end Parent;
>
> > generic
> > Parent.Child is
> > ...
> > end Parent.Child;
>
> > I can see P declarations inside Parent, but in Child I need to prefix
> > everything with 'P.', even if I add a use-clause.
> > This happens with gnat-4.3.0 .
> > Is it normal? How can I "use" P inside Child?
>
> generic
> Parent.Child is
>   use P;
> end Parent.Child;

I compiled the following
-----%<-----%<-----%<-----%<-----%<
-- SIGNATURE PACKAGE
generic
type T is private;
with function F(X : T) return T;
package Q is end Q;

-- PARENT
with Q;
with Ada.Text_IO;
generic
with package P is new Q(<>);
use P;
package Parent is

procedure A (X : T);
end Parent;

package body Parent is

procedure A (X : T) is
C : T := F(X);
begin
Ada.Text_IO("Hello");
end A;

end Parent;

-- CHILD
generic
package Parent.Child is
use P;
function B(X : T) return T;
end Parent.Child;

package body Parent.Child is

function B(X : T) return T is
use P;
D : T := F(X);
begin
return F(D);
end B;
end Parent.Child;

-- INSTANTIATION
with Parent.Child;
with Q;

procedure Main is
function Incf(X : Integer) return Integer is begin return X + 1;
end Incf;
package R is new Q(Integer, Incf);
package Par is new Parent(R);
package Ch is new Par.Child;
begin
null;
end Main;
-----%<-----%<-----%<-----%<-----%<

and the compiler replied

-----%<-----%<-----%<-----%<-----%<
]# gnatmake main.adb
gcc -c main.adb
main.adb:9:05: instantiation error at parent-child.adb:6
main.adb:9:05: "F" is not visible (more references follow)
main.adb:9:05: instantiation error at parent-child.adb:6
main.adb:9:05: non-visible declaration at q.ads:3
gnatmake: "main.adb" compilation error
-----%<-----%<-----%<-----%<-----%<

Am I missing something?
From: Georg Bauhaus on
Andrea Taverna schrieb:

> and the compiler replied
>
> -----%<-----%<-----%<-----%<-----%<
> ]# gnatmake main.adb
> gcc -c main.adb
> main.adb:9:05: instantiation error at parent-child.adb:6
> main.adb:9:05: "F" is not visible (more references follow)
> main.adb:9:05: instantiation error at parent-child.adb:6
> main.adb:9:05: non-visible declaration at q.ads:3
> gnatmake: "main.adb" compilation error
> -----%<-----%<-----%<-----%<-----%<
>
> Am I missing something?

It's not a "use" issue I think. P.F is marked invisible,
too. Can you try this:

generic
with package P is new Q(<>);
use P;
package Parent is

function P_F(X : P.T) return P.T
renames P.F;


and then call P_F in place of F.

I think it has (remotely?) to do with an issue hat Eric Hughes
had with Ada formal packages when trying C++ patterns;
IIRC, it was not reported to the producers of the compiler.
Also, there seems to have been some change in Ada 2005 LRM
12.7 from Ada 95 around the (<>) of a generic formal package,
but I don't know whether that is matters here.
From: Andrea Taverna on
On 16 Dic, 14:14, Georg Bauhaus <rm.dash-bauh...(a)futureapps.de> wrote:
> Andrea Taverna schrieb:
>
> > and the compiler replied
>
> > -----%<-----%<-----%<-----%<-----%<
> > ]# gnatmake main.adb
> > gcc -c main.adb
> > main.adb:9:05: instantiation error at parent-child.adb:6
> > main.adb:9:05: "F" is not visible (more references follow)
> > main.adb:9:05: instantiation error at parent-child.adb:6
> > main.adb:9:05: non-visible declaration at q.ads:3
> > gnatmake: "main.adb" compilation error
> > -----%<-----%<-----%<-----%<-----%<
>
> > Am I missing something?
>
> It's not a "use" issue I think.  P.F is marked invisible,
> too.
I'm not sure I understand you correctly here, however P.F *is*
visible, in fact the compiler stops complaining after prefixig P's
name to F.

>  Can you try this:
>
> generic
>    with package P is new Q(<>);
>    use P;
> package Parent is
>
>    function P_F(X : P.T) return P.T
>      renames P.F;
>
> and then call P_F in place of F.

I'd rather rename P to a shorter name.

thanks,

Andrea