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,87cefb21a3c43af8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!amsnews11.chello.com!newsfeed01.chello.at!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Trouble with overriding and class-wide parameters 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: <44b91f16$0$27041$626a54ce@news.free.fr> Date: Sat, 15 Jul 2006 20:00:03 +0200 Message-ID: NNTP-Posting-Date: 15 Jul 2006 20:00:02 MEST NNTP-Posting-Host: 4430dccf.newsread2.arcor-online.net X-Trace: DXC=U_i_=OC2>JRghFd\k@b23TQ5U85hF6f;TjW\KbG]kaMXGSi?jHD8GOP^?I>]aDN]g\[6LHn;2LCV^[ On Sat, 15 Jul 2006 19:00:00 +0200, Yves Bailly wrote: > Hello all, > > Here's a problem I'm encountering, while developping a (rather > huge) library using Ada 2005, for now using only the latest GNAT > GPL compiler from AdaCore (i.e. GNAT-2006). > > Given a first package, defining a tagged type: > --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- > package Pkg is > type Some_Type is tagged null record; > not overriding > procedure Setup(st: not null access Some_Type; > p : access Some_Type'Class); > end Pkg; > --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- > The procedure just Put_Line() a string to identify itself. > > Then take a second package, with a type derived from the previous: > --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- > with Pkg; use Pkg; > package Sub_Pkg is > type Sub_Type is new Some_Type with null record; > not overriding > procedure Setup(st: not null access Sub_Type; > p : access Sub_Type'Class); > end Sub_Pkg; > --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- > Here again the procedure just print something to identify itself. > > Now the test program: > --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- > with Pkg; use Pkg; > with Sub_Pkg; use Sub_Pkg; > procedure Test is > st: aliased Sub_Type; > begin > st.Setup(null); > end Test; > --8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<--- > > I would expect the call to Setup() to invoke the Sub_Pkg.Setup() > procedure, as "st" is of type Sub_Type. However the procedure > actually called is Pkg.Setup(), as shown by the output : > Pkg.Setup(Some_Type) > > What am I missing? I suspect the value "null" to be part of this, > but I can't find a workaround. What are you trying to achieve? The code looks wrong to me. Why are you using access types in a procedure? Why do you want to overload two different Setup? If the second parameter has to be covariant then Ada does support it: procedure Setup (St : in out Some_Type; p : in out Some_Type); If you want it contravariant Ada supports that as well: procedure Setup (St : in out Some_Type; p : in out Some_Type'Class); -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de