comp.lang.ada
 help / color / mirror / Atom feed
* type extension at deeper accessibility level than parent
@ 2004-05-04  9:47 Xaelis
  2004-05-04 12:33 ` Martin Krischik
  2004-05-04 18:35 ` Stephen Leake
  0 siblings, 2 replies; 3+ messages in thread
From: Xaelis @ 2004-05-04  9:47 UTC (permalink / raw)


Hi,

I don't understand why i can't do somthing like that :

-- a.ads

package A is
   type X is abstract tagged null record;
end A;

-- b.ads

with A;

generic
   type P is private;
package B is
   type Y is new A.X with null record;
end B;

--  essai.adb

with B;

procedure Essai is
   package C is new B (Integer);
begin
   null;
end Essai;

I have :
essai.adb:4:04: instantiation error at b.ads:6
essai.adb:4:04: type extension at deeper accessibility level than parent

I don't know why is it a problem and who to solve it.
Thanks for your help.

-- 
Alexis Muller
Laboratoire d'Informatique Fondamentale de Lille (LIFL)
Universite de Lille 1 - 59655 Villeneuve d'Ascq Cedex
Web : http://www.lifl.fr/~mullera




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: type extension at deeper accessibility level than parent
  2004-05-04  9:47 type extension at deeper accessibility level than parent Xaelis
@ 2004-05-04 12:33 ` Martin Krischik
  2004-05-04 18:35 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: Martin Krischik @ 2004-05-04 12:33 UTC (permalink / raw)


Xaelis wrote:

> Hi,
> 
> I don't understand why i can't do somthing like that :
 
> I have :
> essai.adb:4:04: instantiation error at b.ads:6
> essai.adb:4:04: type extension at deeper accessibility level than parent
> 
> I don't know why is it a problem and who to solve it.

The error message says it all. package C need to be on the same level as A
and B. Depending on your compiler this could untimatly mean you have to
write:

packageᅵCᅵisᅵnewᅵBᅵ(Integer);

all alone into its own file. 

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: type extension at deeper accessibility level than parent
  2004-05-04  9:47 type extension at deeper accessibility level than parent Xaelis
  2004-05-04 12:33 ` Martin Krischik
@ 2004-05-04 18:35 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Leake @ 2004-05-04 18:35 UTC (permalink / raw)
  To: comp.lang.ada

Xaelis <Alexis.Muller@nospam.lifl.fr> writes:

> Hi,
> 
> I don't understand why i can't do somthing like that :
> 
> -- a.ads
> 
> package A is
>    type X is abstract tagged null record;
> end A;
> 
> -- b.ads
> 
> with A;
> 
> generic
>    type P is private;
> package B is
>    type Y is new A.X with null record;
> end B;
> 
> --  essai.adb
> 
> with B;
> 
> procedure Essai is
>    package C is new B (Integer);
> begin
>    null;
> end Essai;
> 
> I have :
> essai.adb:4:04: instantiation error at b.ads:6
> essai.adb:4:04: type extension at deeper accessibility level than parent

"accessibility level" here refers to the position of variables and
subprograms on the stack.

A and Essai are "library level"; they are on the heap, not the stack.

Essai.C is one subprogram down; it is not at library level.

> I don't know why is it a problem 

Since package C is declared in a _procedure_, the subprograms it
declares will not exist after the procedure exits (package B doesn't
actually declare any subprograms, but the compiler assumes it will at
some point). Since A.X is a tagged type, at some point the compiler
might try to dispatch thru a global variable of type A.X'class to a
subprogram in Essai.C, which might not exist. So it's illegal.

> and who to solve it. 

Declare package C at library level:

package C si new B (Integer);

with C; use C;
procedure Essai is
begin
   null;
end Essai;

> Thanks for your help.

You're welcome. This is one area where Ada is confusing. But it is an
example of the rules of Ada preventing you from using dangling
pointers. 

-- 
-- Stephe




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-05-04 18:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-04  9:47 type extension at deeper accessibility level than parent Xaelis
2004-05-04 12:33 ` Martin Krischik
2004-05-04 18:35 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox