From: Jere <jhb.chat@gmail.com>
Subject: Package formal parameter visibility
Date: Sun, 26 Mar 2017 14:06:42 -0700 (PDT)
Date: 2017-03-26T14:06:42-07:00 [thread overview]
Message-ID: <7f095a51-f906-47b6-ac21-a8e07dc46726@googlegroups.com> (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
next reply other threads:[~2017-03-26 21:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-26 21:06 Jere [this message]
2017-03-26 21:47 ` Package formal parameter visibility Robert A Duff
2017-03-26 21:56 ` Jere
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox