From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,43aafc250d42730f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-02-10 01:55:15 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!news.belnet.be!psinet-eu-nl!news.imp.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!not-for-mail From: t_wolf@my-deja.com (Thomas Wolf) Newsgroups: comp.lang.ada Subject: Re: controlled type in generic package? Date: Sat, 10 Feb 2001 09:54:54 GMT Organization: --- Message-ID: <3a85091d.852056202@paragate1> References: <3A7FDA9A.C667090F@stn-atlas.de> <95p2ab$463$1@nnrp1.deja.com> <95q1fa$9e$1@usenet.rational.com> <95rpj5$gq7$1@nnrp1.deja.com> <95sjs9$ral$1@wanadoo.fr> Reply-To: t_wolf@my-deja.com NNTP-Posting-Host: kukclu.paranor.ch X-Trace: pollux.ip-plus.net 981798675 8407 195.65.4.173 (10 Feb 2001 09:51:15 GMT) X-Complaints-To: news@ip-plus.net NNTP-Posting-Date: 10 Feb 2001 09:51:15 GMT X-Newsreader: Forte Free Agent 1.11/32.235 Xref: supernews.google.com comp.lang.ada:5096 Date: 2001-02-10T09:51:15+00:00 List-Id: 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