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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8f7d6c5172a1d41b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news4.google.com!news.glorb.com!news.cs.univ-paris8.fr!proxad.net!proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: [Revisited] How to get around "access type must not be outside generic unit" Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <3vwf1b4b2ntl$.l9n17zmh9v8a$.dlg@40tude.net> <1u2mhr9ypij4u.bn3yayn7o9l3$.dlg@40tude.net> Date: Thu, 25 Jan 2007 12:07:19 +0100 Message-ID: NNTP-Posting-Date: 25 Jan 2007 12:07:19 CET NNTP-Posting-Host: 1708cf7f.newsspool4.arcor-online.net X-Trace: DXC=>VeI>1JUZ>jEB;5>eE0T7m4IUKkgbgaZR]3LF5eo X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8542 Date: 2007-01-25T12:07:19+01:00 List-Id: On Wed, 24 Jan 2007 14:50:49 -0600, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:1u2mhr9ypij4u.bn3yayn7o9l3$.dlg@40tude.net... > ... >>> But in any case, the solution to your problem (as always) is to put the >>> 'Access into the private part of the specification. Do that with an >>> appropriate constant declaration. (If the parameter type of Register was >>> anonymous, there is no problem, so there must be a named type that can be >>> used.) Doing so will force the generic to be instantiated at the library >>> level. >> >> OK, that's definitely better than Unchecked_Conversion. In Ada 95 it was >> enough to add a declaration of the subprogram to the specification, now we >> also need an access object. This is strange, at least not obvious. Why >> should it change anything? > > Because it's part of the contract model. > > That is assume-the-best in the > visible part of the spec, and assume-the-worst in the body. (We're somewhat > confused about the private part.) Whenever we assume-the-best, there is a > required recheck in the instance. > > Thus, putting such a 'Access in the spec means that it will be rechecked and > rejected if it causes trouble. In this case, that means that the generic > will be rejected if it is instantiated in a nested scope. Hmm, I don't think it is a contract. To be a contract "I want X'Access" should be in the generic formal part. It is closer to how C++ templates work. (for "I want X'Access" there even exists a reserved keyword) But that's no matter. >> I mean, if it is semantically correct, then why >> the compiler cannot deduce it? Is it semantically correct? In the case with >> Glib above, would it be possible to instantiate a generic package in a >> local scope; call to Boxed_Type_Register_Static passing a constant as you >> described; and then leave the scope? > > No, the instance will be rejected at compile-time as failing an > accessibility check. [...] I see, thank you for explanation. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de