comp.lang.ada
 help / color / mirror / Atom feed
* Dynamic_Predicate and dispatching call
@ 2016-11-07 15:00 Duckysmokton
  2016-11-07 15:34 ` Egil H H
  0 siblings, 1 reply; 3+ messages in thread
From: Duckysmokton @ 2016-11-07 15:00 UTC (permalink / raw)


Hello,

I have a confusing issue with an Ada 2012 / GNAT 2016 program.

Given a tagged type that has :
* an abstract method that makes an unspecified calculation
* a non-abstract method that performs a dispatching call to this calculation
* a Dynamic_Predicate

package Test_Dispatch is

   type t_Element_Array is array (Natural range <>) of Integer;

   type t_Base_Object is abstract tagged private;

   function get_One_Value (Self    : in t_Base_Object;
                           Element : in Natural)
                           return Integer is abstract;

   function get_All_Values (Self : in t_Base_Object)
                            return t_Element_Array
     with Extensions_Visible; -- needed for dispatching call

private

   type t_Base_Object is abstract tagged record
      Element_Count : Positive;
   end record
     with Dynamic_Predicate => (t_Base_Object.Element_Count mod 2 = 0);

end Test_Dispatch;

package body Test_Dispatch is

   function get_All_Values (Self : in t_Base_Object)
                            return t_Element_Array is
   begin
      return Answer : t_Element_Array (0..Self.Element_Count-1) do
         for Element in Answer'Range loop
            Answer (Element) :=
            t_Base_Object'Class(Self).get_One_Value (Element);
         end loop;
      end return;
   end get_All_Values;

end Test_Dispatch;

Compilation fails on "t_Base_Object'Class(Self)." with :
class-wide argument not allowed here

If I remove the Dynamic_Predicate, it's OK.
ARM does not mention restriction on dispatching calls and dynamic predicates, so, what is the problem ?
Thanks for any advice.

PS:
- It also occurs if get_One_Value is not abstract (returns a defaultvalue)
- get_All_Values parameter Self shall not be class-wide because it is a default method and derived objects might implement more efficient or appropriate algorithms

(Troll bait : this would not happen with C++ !)

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

end of thread, other threads:[~2016-11-15 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-07 15:00 Dynamic_Predicate and dispatching call Duckysmokton
2016-11-07 15:34 ` Egil H H
2016-11-15 13:12   ` Duckysmokton

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