Order matters on inheritance

Regan Heath regan at netmail.co.nz
Thu Aug 22 01:45:34 PDT 2013


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.

Regan

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list