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.8 required=5.0 tests=BAYES_00,PLING_QUERY autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d74cdcee29b02bcc X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!i12g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Discriminant ans tagged type ?! Date: Tue, 18 Mar 2008 08:54:53 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <47dfde3d$0$26828$426a74cc@news.free.fr> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1205855693 19777 127.0.0.1 (18 Mar 2008 15:54:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 18 Mar 2008 15:54:53 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i12g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20467 Date: 2008-03-18T08:54:53-07:00 List-Id: On Mar 18, 8:22 am, Tony wrote: > I just do not understand why the following code compiles with the Aonix > compiler and not with the Gnat GPL 2007? Because one of the compilers has a bug. Or did you want a *helpful* answer??? :) :) :) > > package A_Pkg is > type A (L : Natural) is tagged null record; > end A_Pkg; > > package A_Pkg.B_Pkg is > type B is new A with record > T : String(1..L); > end record; > end A_Pkg.B_Pkg; > > with A_Pkg.B_Pkg; > procedure Strange is > begin > null; > end Strange; > > => RM95 3.7 (18) ?? Yes, B inherits the discriminant L, but this doesn't make L *visible*. In order to use L by itself, as you did in the definition of the component T, L has to be directly visible. The rules for this are in 8.1 and 8.2, and aren't easy to understand. The applicable rules here are that: The declaration of L (when the discriminant is first declared) is visible up to the end of the declarative region immediately enclosing it, which is the definition of the type A. But this declarative region does *not* encompass the declarations of any type extensions. (Also, the fact that B "inherits" L is not equivalent to there being an implicit declaration of L; unlike inherited subprograms, inherited discriminants aren't implicitly declared.) Thus, L is not directly visible within the declaration of B. However, I tried changing the declaration of T as follows: T : String (1 .. B.L); and GNAT accepted it. (I haven't done enough testing to make sure GNAT handles it correctly in other ways, though.) Here, B refers to the "current instance" of the type (8.6(17)), and 3.7(18) means that all instances of the type will have a component L that is inherited from A, so this should be legal unless there are some other rules that I've missed (and that GNAT also missed). Hope this helps, -- Adam