comp.lang.ada
 help / color / mirror / Atom feed
From: Yves Bailly <kafka.fr@laposte.net>
Subject: Trouble with overriding and class-wide parameters
Date: Sat, 15 Jul 2006 19:00:00 +0200
Date: 2006-07-15T19:00:07+02:00	[thread overview]
Message-ID: <44b91f16$0$27041$626a54ce@news.free.fr> (raw)

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.

Sorry in advance if it's a silly question, I have a huge background
of C++ and not yet very skilled with Ada type system.

Thanks for any hint !

Best regards,

-- 
(o< | Yves Bailly  : http://kafka-fr.net   | -o)
//\ | Linux Dijon  : http://www.coagul.org | //\
\_/ |                                      | \_/`



             reply	other threads:[~2006-07-15 17:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-15 17:00 Yves Bailly [this message]
2006-07-15 18:00 ` Trouble with overriding and class-wide parameters Dmitry A. Kazakov
2006-07-15 18:20   ` Yves Bailly
2006-07-15 19:12     ` Dmitry A. Kazakov
2006-07-15 18:52 ` Jeffrey R. Carter
2006-07-15 20:03   ` Yves Bailly
2006-07-16  0:20     ` Jeffrey R. Carter
2006-07-16 10:00 ` Javier Miranda
2006-07-16 12:11   ` Ludovic Brenta
2006-07-16 13:36     ` Javier Miranda
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox