comp.lang.ada
 help / color / mirror / Atom feed
From: t_wolf@my-deja.com (Thomas Wolf)
Subject: Re: controlled type in generic package?
Date: Sat, 10 Feb 2001 09:54:54 GMT
Date: 2001-02-10T09:51:15+00:00	[thread overview]
Message-ID: <3a85091d.852056202@paragate1> (raw)
In-Reply-To: 95sjs9$ral$1@wanadoo.fr

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2355 bytes --]

On Wed, 7 Feb 2001 23:52:36 +0100, "Jean-Pierre Rosen"
<rosen.adalog@wanadoo.fr> wrote:

>
>"Ted Dennison" <dennison@telepath.com> 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 <t_wolf@my-deja.com>



      parent reply	other threads:[~2001-02-10  9:54 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-06 11:06 controlled type in generic package? Nils Priebe
     [not found] ` <slrn97vtf5.ho.lutz@taranis.iks-jena.de>
     [not found]   ` <95q19j$9d$1@usenet.rational.com>
2001-02-07 10:11     ` Lutz Donnerhacke
2001-02-07 21:57       ` Mark Lundquist
     [not found]   ` <95p2ab$463$1@nnrp1.deja.com>
2001-02-07 15:08     ` Jean-Pierre Rosen
2001-02-08 15:41       ` Ted Dennison
2001-02-08 18:21         ` Jean-Pierre Rosen
2001-02-08 16:31       ` Florian Weimer
2001-02-08 21:10       ` Brian Rogoff
2001-02-09 10:39         ` Florian Weimer
2001-02-09 17:02           ` Brian Rogoff
2001-02-09 18:45             ` Florian Weimer
2001-02-13  0:32           ` Nick Roberts
2001-02-14  0:30             ` Jon S Anthony
     [not found]               ` <x7vg0hd20cm.fsf@smaug.pushface.org>
     [not found]                 ` <hovk6.96$aw5.304@www.newsranger.com>
2001-02-23 20:50                   ` Simon Wright
     [not found]     ` <95q1fa$9e$1@usenet.rational.com>
2001-02-07 15:28       ` Ted Dennison
2001-02-07 16:29         ` Brian Rogoff
     [not found]           ` <3A82A66D.49DE7EBD@bton.ac.uk>
2001-02-08 15:15             ` Robert Dewar
2001-02-08 16:56             ` Florian Weimer
2001-02-09 10:25               ` John English
2001-02-09 19:46                 ` Brian Rogoff
2001-02-07 18:52         ` Pat Rogers
2001-02-07 19:23           ` Pat Rogers
2001-02-07 19:50             ` Ted Dennison
2001-02-07 22:52         ` Jean-Pierre Rosen
2001-02-08  9:36           ` dmitry6243
2001-02-09  8:51             ` Jean-Pierre Rosen
2001-02-09 12:28               ` dmitry6243
2001-02-08 19:58           ` Mark Lundquist
2001-02-10  9:54           ` Thomas Wolf [this message]
replies disabled

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