Page 1 of 1

Order of delegation and inheritance: does it matter?

Posted: 6 Mar 2015 13:56
by Peter Muraya
Hi all,
Does the order of delegating interfaces to facts matter? And if so, why is it not the case for inheritance? I ask these questions because my program behaved unexpectedly when I used delegation rather than inheritance and I could not figure out a very logical explanation for this.

In the sample below, I have an interface, called fruit, that supports two other interfaces, male and female, which in turn supports a third interface, sex. I have implemented the fruit interface using 3 different ways:

(1) By delegation, where the compiler reports no errors (except for the warning that male and female facts are not used)

(2) By inheritance, and the compile returns a very helpful message: An ambiguous inheritance of the predicate or property definition sex::name (i)' in the class 'fruit' (from classes 'male' and 'female')

(3) By inheritance using the error message in 2 to help me make a rational decision about how a fruit should behave.

Code: Select all

interface sex properties     name:string. end interface   class sex:sex end class   implement sex facts      name:string:=class_name(). end implement /********************************************/   interface male supports sex end interface male   class male:male end class   implement male inherits sex end implement   /********************************************/   interface female supports sex end interface   class female:female end class   implement female inherits sex end implement   /********************************************/   interface fruit supports male, female constants     version:integer = 2. end interface   class fruit:fruit end class   #if fruit::version=1 #then      implement fruit           facts                male:male:=erroneous.                female:female:=erroneous.             delegate interface male to male           delegate interface female to female      end implement fruit #endif   #if fruit::version=2 #then      implement fruit inherits male, female      end implement fruit #endif   #if fruit::version=3 #then      implement fruit inherits male, female           resolve interface sex from male      end implement fruit #endif   /********************************************/   goal     succeed().

Posted: 6 Mar 2015 21:24
by Thomas Linder Puls
There is clearly a problem here. And I am afraid that I don't have a good answer.

It is not the intention that the order should matter: Version 1 should also give an error. And you would then have to be explicit about the ambiguity:

Code: Select all

    delegate         interface male to male,         interface female to female,         interface sex to male
But if you write like that you will get an error.

We will of course look into this, but that will not help you now.

Order of delegation and inheritance: does it matter?

Posted: 7 Mar 2015 10:24
by Peter Muraya
Thanks Thomas.
Ok, so the order matters, and on further investigation, I have seen that it is first-delegation-comes-first. I can live with the problem, until it is fixed, but is there some sort of guarantee that this order always stay them same?

Posted: 7 Mar 2015 20:01
by Thomas Linder Puls
The compiler you have will do things in a certain way, and the next will do it in the right way :-).

Order of delegation and inheritance: does it matter?

Posted: 8 Mar 2015 10:36
by Peter Muraya
The message is clear: no guarantee. Thanks.

Posted: 24 Nov 2015 14:18
by Thomas Linder Puls
This fixed in build 7502.