comp.lang.ada
 help / color / mirror / Atom feed
From: Duckysmokton <duckysmokton@free.fr>
Subject: Dynamic_Predicate and dispatching call
Date: Mon, 7 Nov 2016 07:00:48 -0800 (PST)
Date: 2016-11-07T07:00:48-08:00	[thread overview]
Message-ID: <f633ac77-7aea-42a4-8902-548efa377cee@googlegroups.com> (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++ !)

             reply	other threads:[~2016-11-07 15:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-07 15:00 Duckysmokton [this message]
2016-11-07 15:34 ` Dynamic_Predicate and dispatching call Egil H H
2016-11-15 13:12   ` Duckysmokton
replies disabled

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