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,9491b94351596175 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!y23g2000pre.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: A problem with "interface" Date: Thu, 5 Feb 2009 08:14:56 -0800 (PST) Organization: http://groups.google.com Message-ID: References: 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 1233850497 30222 127.0.0.1 (5 Feb 2009 16:14:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 5 Feb 2009 16:14:57 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y23g2000pre.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:3569 Date: 2009-02-05T08:14:56-08:00 List-Id: On Feb 5, 7:05 am, Robert_Matthews wrote: > In using interface types with GNAT I have encountered a problem. > Consider the following packages: > > package Int is > > type A is interface; > type B is interface; > > procedure P (Param1 : A; Param2 : B'Class) is abstract; > > end Int; > > with Int; > package Client is > > type Client_A is new Int.A with null record; > type Client_B is new Int.B with null record; > > overriding > procedure Client_P (Param1 : Client_A; Param2 : Client_B'Class); > > end Client; > > On compiling, GNAT says "Client_P" does not override anything. > Am I making a dumb mistake here - or is it GNAT? You're making a mistake, but I'm hesitant to call it a "dumb" one. When you declare Client_A, the package implicitly declares inherited operations, which are inherited from primitive operations of Int.A. One of those is Client_P, and so you'll get this *implicit* declaration; procedure Client_P (Param1 : Client_A; Param2 : Int.B'Class); Since Client_A is derived from Int.A, all uses of "A" in the profile are replaced by Client_A. But "B" isn't touched. Note that nothing is inherited when you declare Client_B. Client_P is a primitive operation of Int.A but *not* of Int.B (since its parameter is B'Class, not B). When you declare an overriding procedure, the procedure has to override something that is implicitly declared. The only implicitly declared procedure is the one I showed above; its second parameter has type Int.B'Class, not Client_B'Class, and therefore the procedure you declared can't override it. The way to do this is to declare your procedure with "Param2 : Int.B'Class"; then in the body of Client_P, you can say something like if Param2 not in Client_B'Class then raise with "Wrong client type"; end if; -- Adam