comp.lang.ada
 help / color / mirror / Atom feed
* Trouble with overriding and class-wide parameters
@ 2006-07-15 17:00 Yves Bailly
  2006-07-15 18:00 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Yves Bailly @ 2006-07-15 17:00 UTC (permalink / 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 | //\
\_/ |                                      | \_/`



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-07-16 13:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-15 17:00 Trouble with overriding and class-wide parameters Yves Bailly
2006-07-15 18:00 ` 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

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