www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Order matters on inheritance

reply "JS" <js.mdnq gmail.com> writes:
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.
Aug 21 2013
next sibling parent "Infiltrator" <Infiltrator d.irc> writes:
On Thursday, 22 August 2013 at 01:43:45 UTC, JS 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.
There is a bug out for this. Please upvote it. :) http://d.puremagic.com/issues/show_bug.cgi?id=10806
Aug 21 2013
prev sibling parent reply "Regan Heath" <regan netmail.co.nz> writes:
On Thu, 22 Aug 2013 02:43:42 +0100, JS <js.mdnq 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/
Aug 22 2013
parent "JS" <js.mdnq gmail.com> writes:
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 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.
Aug 22 2013