On Wed, 7 Feb 2001 23:52:36 +0100, "Jean-Pierre Rosen" wrote: > >"Ted Dennison" a �crit dans le message news: 95rpj5$gq7$1@nnrp1.deja.com... >> I have to admit I'm a little unclear as to what nasty things could >> happen to me if I were allowed to declare a derived tagged type at a >> lower scope level than their parent type. >OK, let's go: > >package body Pack is > type Parent is tagged ...; > procedure Proc (X : Parent) is ... end Proc; > > type Ptr is access Parent'Class; > V : Ptr; > > procedure P is > type Child is new Parent with...; > procedure Proc (X : Child) is... end Proc; > begin > V := new Child; > end P; > >begin > P; >-- Now, V.all points to an object of type P.Child >-- We can call Proc (V.all) which will result in a dispatching call to P.Proc, but P is out of scope at this point !!! Dabbling in language design is fun :-) It seems to me that this case could be handled by the already existing accessibility level rules for access types. After all, type Child has a level that is statically deeper than that of type Ptr, so the assignment might simply be disallowed. Of course, one could still play tricks with 'Unchecked_Access, but then, it's always been the developers' responsibility to get things right when using 'Unchecked_Access! As to P.Proc being out of scope: I guess this could be detected at run-time. At least an implementation using static links could detect that the static link in a call Proc (V.all) is null, and raise an exception. A similar solution probably also exists for implementations using displays. I see a more serious problem with package body Pack is type Parent is tagged ...; function Create return Parent'Class is type Child is new Parent with ...; Result : Child; begin return Result; end; P : Parent'Class := Create; end Pack; But even this could perhaps be handled by extending the accessibility rule to class-wide types, too. Are you aware that there is an AI on downward closures for subprogram access types and limited tagged types (AI-00254)? It seems to me that this AI has some relevance to this issue. As for downward closures on subprogram access types: IIRC, Oberon (from Wirth at ETH Zurich) had this. -- Dr. Thomas Wolf