Order matters on inheritance

JS js.mdnq at gmail.com
Thu Aug 22 08:15:46 PDT 2013


On Thursday, 22 August 2013 at 08:45:36 UTC, Regan Heath wrote:
> On Thu, 22 Aug 2013 02:43:42 +0100, JS <js.mdnq at gmail.com> 
> wrote:
>
>> I don't know what the expected behavior is but it seems 
>> odd/wrong:
>>
>> http://dpaste.dzfl.pl/a390f1f4
>>
>> Note that there are two issues here(almost the same). First is 
>> that A.foo isn't called and second is that the order of 
>> inheritance on A matters(: X, Y vs : Y,X).
>>
>>
>> I would expect that A.foo(A) should match first and the 
>> ambiguity created from the inheritance should result in an 
>> error.
>
> I disagree that a.foo(A) should match, because..
>
> You have a variable 'q' of type (interface) 'A' and you call 
> method 'foo' on it.  The compiler MUST only consider methods 
> available on type (interface) 'A', which are:
>   foo(X)
>   foo(Y)
> It cannot call a.foo(A) (note 'a.foo' not 'A.foo') because 
> while 'q' does in reality refer to an object of type 'a', 
> you've asked it to interface to it via it's interface 'A' which 
> does not have an overload foo(A).
>
> I do however agree that the compiler behaviour of silently 
> selecting the foo from the first interface listed is wrong, it 
> ought to give an error in this case IMO.
>

Right, I forgot to add foo(A) to the interface. (I added it very 
quickly after the fact)

It works as expected when foo(A) is added to the interface so 
there is no problem with that aspect.


More information about the Digitalmars-d-learn mailing list