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,14fb9d67ad36043 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!s21g2000prm.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Object.Operation and child package Date: Wed, 25 Jun 2008 12:03:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <87vdzx9x3n.fsf@ludovic-brenta.org> 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 1214420605 4903 127.0.0.1 (25 Jun 2008 19:03:25 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 25 Jun 2008 19:03:25 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s21g2000prm.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:883 Date: 2008-06-25T12:03:24-07:00 List-Id: On Jun 25, 11:40 am, Ludovic Brenta wrote: > pascal.mala...@gmail.com writes: > > Hi Ada05 experts, > > > Is it normal to reject compilation of Object.Operation notation when > > operation is in a child package: > > > package Pack is > > type Typ is tagged null record; > > procedure Proc1 (Var : in Typ); > > end Pack; > > > package Pack.Sub is > > procedure Proc2 (Var : in Typ); > > end Pack.Sub; > > > with Pack.Sub; > > procedure Proc is > > Obj : Pack.Typ; > > begin > > Obj.Proc1; > > Obj.Proc2; > > end Proc; > > > The second call does not compile (with gnat): > > proc.adb:6:04: no selector "Proc2" for type "Typ" defined at pack.ads: > > 3 > > Yes, this is normal because Proc2 is not a primitive operation of Typ > (or, in other words, it is not a method of Typ). A primitive > operation, by definition, is declared in the same package as its type. "Primitive operation" is the wrong concept here. First of all, the subprogram only has to be declared in the same declarative region as the type, or an ancestor of the type. The "same declarative region" can be in a procedure body or package body, which makes them not primitive operations since primitive operations have to be in a package specfication. Also, the subprogram can be a subprogram whose first parameter is Typ'Class; those are not primitive operations of Typ, but they can be used in Object.Operation notation. Finally, a subprogram can be a primitive operation of Typ even if its second parameter (or third, etc.) has the right type, or if it's a function that returns Typ; but it can't be used in Object.Operation notation unless the *first* parameter has the right type. But in this case, yes, since Proc2 isn't declared in the same package as Typ, it can't be used. -- Adam