* Package formal parameter visibility
@ 2017-03-26 21:06 Jere
2017-03-26 21:47 ` Robert A Duff
0 siblings, 1 reply; 3+ messages in thread
From: Jere @ 2017-03-26 21:06 UTC (permalink / raw)
I ran into something that interested me while dorking around
with some Ada code. The error makes sense when I think about it,
but I ran into what looks like an inconsistency on the surface.
Consider the package:
##################
generic
type My_Type is limited private;
with procedure Do_Something(Instance : in out My_Type);
package Package_A is
subtype My_Subtype is My_Type;
end Package_A;
#####################
It doesn't do much on its own and if I try to use it like so:
#####################
with Package_A;
procedure Main is
procedure Do_Something(Instance : in out Integer) is
begin
Instance := 23;
end Do_Something;
package A is new Package_A(My_Type => Integer,
Do_Something => Do_Something);
Var : A.My_Subtype;
begin
A.Do_Something(Var);
end Main;
######################
I get the error: "Do_Something" is not a visible entity of "A"
Fair enough, I can't use formal parameters in a client directly.
If I want to, I have to either use some rename clauses or wrapper
procedures.
Tben I noticed I could do it if another generic package used it in this
manner:
###################################
with Package_A;
generic
with package A is new Package_A(<>);
package Package_B is
procedure Do_Something;
end Package_B;
###################################
###################################
package body Package_B is
procedure Do_Something is
Var : A.My_Subtype;
begin
A.Do_Something(Var); -- Shouldn't I get the error here?
end Do_Something;
end Package_B;
###################################
If I use A as a formal parameter into another package, I suddenly get
visibility of A's formal parameters in that new package. But isn't
package B kind of a client of A in this scenario or does another rule
apply here? NOTE: I realize I might be using the word "client"
inappropriately here. I don't know the right terminology, so I hope
at least the intent of my question is clear enough.
Using GNAT GPL 2016 for compilation if it makes a difference
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Package formal parameter visibility
2017-03-26 21:06 Package formal parameter visibility Jere
@ 2017-03-26 21:47 ` Robert A Duff
2017-03-26 21:56 ` Jere
0 siblings, 1 reply; 3+ messages in thread
From: Robert A Duff @ 2017-03-26 21:47 UTC (permalink / raw)
Jere <jhb.chat@gmail.com> writes:
> If I use A as a formal parameter into another package, I suddenly get
> visibility of A's formal parameters in that new package.
Yes, formal packages are treated differently. If you want to know the
exact rules, and why, read AARM-12.7(10-10.b).
- Bob
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Package formal parameter visibility
2017-03-26 21:47 ` Robert A Duff
@ 2017-03-26 21:56 ` Jere
0 siblings, 0 replies; 3+ messages in thread
From: Jere @ 2017-03-26 21:56 UTC (permalink / raw)
On Sunday, March 26, 2017 at 5:47:51 PM UTC-4, Robert A Duff wrote:
> Jere writes:
>
> > If I use A as a formal parameter into another package, I suddenly get
> > visibility of A's formal parameters in that new package.
>
> Yes, formal packages are treated differently. If you want to know the
> exact rules, and why, read AARM-12.7(10-10.b).
>
> - Bob
Gotcha! Thank you for the section reference!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-26 21:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-26 21:06 Package formal parameter visibility Jere
2017-03-26 21:47 ` Robert A Duff
2017-03-26 21:56 ` Jere
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox