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: 103376,26a21b9e317dc639 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,CP1252 Received: by 10.66.84.202 with SMTP id b10mr241800paz.43.1353372755073; Mon, 19 Nov 2012 16:52:35 -0800 (PST) Received: by 10.50.42.194 with SMTP id q2mr3242761igl.11.1353372754889; Mon, 19 Nov 2012 16:52:34 -0800 (PST) Path: s9ni239pbb.0!nntp.google.com!kr7no141993pbb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 19 Nov 2012 16:52:34 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: <9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada) From: Adam Beneschan Injection-Date: Tue, 20 Nov 2012 00:52:35 +0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Date: 2012-11-19T16:52:34-08:00 List-Id: On Monday, November 19, 2012 3:59:14 PM UTC-8, Randy Brukardt wrote: > >with Some_Package; >=20 > >procedure Main is > > Message : Some_Package.Message_Type; > >begin > > Message.Print; > >end Main; >=20 > > >=20 > >Is it possible to create a parameterless access type to the Message.Prin= t=20 >=20 > >procedure? >=20 > >The following application refuses to compile: >=20 > >with Some_Package; > >procedure Main is > > Message : Some_Package.Message_Type; > > Method_Ref : access procedure :=3D Message.Print'Access; > >begin > > Method_Ref; > >end Main; >=20 > >The error message is: no selector "Print" for type "Message_Type" define= d=20 > >at some_package.ads:3 > I think this should work; if it doesn't, the error has something to do wi= th=20 > conventions. So there is probably a compiler bug here.... > I'm not certain what the convention of this procedure is (it might be=20 > defined to be "intrinsic" somewhere, in which case you couldn't take 'Acc= ess=20 > to it, I can't find such a rule on a quick check of the RM).=20 6.3.1(4): The Intrinsic calling convention represents subprograms that are = =93built in=94 to the compiler. The default calling convention is Intrinsic= for the following: ... 6.3.1(10.1/2) any prefixed view of a subprogram (see 4.1.3). The AARM gives the reason immediately following: =20 Reason: The profile of a prefixed view is different than the =93real=94 pro= file of the subprogram (it doesn't have the first parameter), so we don't w= ant to be able to take 'Access of it, as that would require generating a wr= apper of some sort.=20 > But it surely=20 > exists and should not report that "selector "Print" doesn't exist. Yep, the error message appears to be wrong, but I can sort of understand it= . If the compiler knows that a prefixed view wouldn't be allowed here (as = a prefix to 'Access), then since it has to do name resolution (in case Prin= t is overloaded), it might be using a different search routine than it woul= d use if it were processing a procedure call. Or something like that. =20 > In any case, our intent is that one could use this just like any other = =20 > procedure with the same profile. You can rename it, pass it as a formal= =20 > subprogram, call it of course, etc. So I would expect 'Access to work as= =20 > well, unless the RM explicitly says it does not. I think the necessity of generating a wrapper, possibly a separate wrapper = for every appearance of this kind of 'Access, is why the language designers= decided not to allow it. See AI95-252. It's also why I was suggesting ad= ding a new kind of access type, rather than changing the language to simply= allow 'Access. -- Adam