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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,12d893e9461dcfe6 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.77.230 with SMTP id v6mr1475834paw.20.1344321713682; Mon, 06 Aug 2012 23:41:53 -0700 (PDT) Path: p10ni243pbh.1!nntp.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!ctu-peer!ctu-gate!news.nctu.edu.tw!usenet.stanford.edu!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Access to generic formal parameters in an generic package instantiation Date: Tue, 31 Jul 2012 08:29:46 -0700 (PDT) Organization: http://groups.google.com Message-ID: <597cbe39-60e5-4ac3-bbb6-71b03c57d5b3@googlegroups.com> References: <87a9yi5t7j.fsf@mid.deneb.enyo.de> <50178db2$0$6562$9b4e6d93@newsspool4.arcor-online.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1343748587 29091 127.0.0.1 (31 Jul 2012 15:29:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 31 Jul 2012 15:29:47 +0000 (UTC) In-Reply-To: <50178db2$0$6562$9b4e6d93@newsspool4.arcor-online.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Received-Bytes: 4701 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-31T08:29:46-07:00 List-Id: On Tuesday, July 31, 2012 12:48:04 AM UTC-7, Georg Bauhaus wrote: > Compilers seem to differ on this one, which should be Ada 95. > I am not sure the generics are properly addressing the issue > of type comparison (well, of convertibility). >=20 > > With GNAT's bug boxes currently in the way I can't try the > Ada 2012 features. (Something about failures when testing entity > node kinds.) >=20 >=20 >=20 > generic > type T is private; > Fst, Snd : in T; > package Same_Type is end; >=20 > with Same_Type; > generic > type Ancestor is private; > type T1 is new Ancestor; > type T2 is new Ancestor; > X : T1; > Y : T2; > -- with package Comparison is new Same_Type (T1, T1'(X), T1 (Y)); >=20 > package Ops is > private > package Comparison_1 is new Same_Type (T1, T1'(X), T1 (Y)); > package Comparison_2 is new Same_Type (T2, T2 (X), T2'(Y)); > end; >=20 > with Same_Type, Ops; > procedure Test_G is > type Int is new Integer; > type Chr is new Character; > Two : constant Int :=3D 2; > C : constant Chr :=3D 'c'; > package Test_1 is new Ops (Int, Int, Int, Two, Two); > --!GNAT! package Test_2 is new Ops (Int, Int, Chr, Two, C); GNAT gets a bug box here, but you do realize that the instantiation is ille= gal, right? T2 is supposed to be derived from T1, but Chr is not derived f= rom Int. I'm sure you probably realize this, but it's not clear from your = post what you're trying to show. > package PK is > type root is tagged null record; > type left is new root with null record; > type right is new root with null record; > end PK; > use pK; > > L : Left; > R : Right; > package test_3 is new ops (Root, Left, Right, L, R); I get an "instantiation error" when I try this with GNAT, which is usually = a bad sign. In this case, I think it's a hole in the language. The formal= types are declared without "tagged", so that while compiling the generic, = they're treated as untagged. And for untagged types, any time you have two= types with the same ultimate ancestor, you can convert between them. For = tagged types, the rules are different, though, since downward conversions (= from a type to its descendant) are not generally allowed, since the descend= ant can have new components that a conversion wouldn't be able to supply. = (I'm not sure offhand whether a downward conversion to a null extension is = allowed--I'd have to look it up.) The problem is that a generic formal unt= agged type can have a tagged type as an actual. So in a case like this, wh= ere a generic contains a construct that would be legal for untagged types b= ut illegal for tagged types, the language doesn't seem to prevent error cas= es from coming up. There may be other constructs besides type conversions= that cause problems when an untagged formal has a tagged actual. Anyway, I'll look into this further but will probably send something to Ada= -Comment unless this has been brought up already. I think it could be fixe= d fairly simply. (I'm thinking that adding a rule that a generic formal un= tagged derived type cannot have a tagged type as an actual would work, and = would be unlikely to make any existing code illegal.) -- Adam