digitalmars.D - Inheriting from an interface twice
- Denis Koroskin (29/29) Oct 01 2010 I always thought that in D interface inheritance is always virtual, i.e....
- Trass3r (1/13) Oct 01 2010 Looks fine?! Isn't foo1 == foo2 what you want?
- Simen kjaeraas (5/20) Oct 01 2010 He mentioned that the code asserts. I say this is fishy, but I don't kno...
- Denis Koroskin (6/21) Oct 01 2010 Sadly, opEquals is only defined for Objects, not interfaces:
- Steven Schveighoffer (4/33) Oct 04 2010 I agree, I think you should file a bug on this.
- Denis Koroskin (3/44) Oct 04 2010 Already done: http://d.puremagic.com/issues/show_bug.cgi?id=4979
I always thought that in D interface inheritance is always virtual, i.e. you only inherit it once even if it is specified twice (or more) within hierarchy. Until I got an assertion on the following test (reduced from a real example): interface Foo { } class Bar : Foo { } class Baz : Bar, Foo { } void main() { Baz baz = new Baz(); Bar bar = baz; Foo foo1 = bar; Foo foo2 = baz; assert(foo1 is foo2); } foo1 and foo2 have the same type and point to the same object. Yet they have different addresses. Is it a bug, or a feature? (http://ideone.com/MnnL8 virtual inheritance used, fails otherwise, of course).
Oct 01 2010
void main() { Baz baz = new Baz(); Bar bar = baz; Foo foo1 = bar; Foo foo2 = baz; assert(foo1 is foo2); } foo1 and foo2 have the same type and point to the same object. Yet they have different addresses. Is it a bug, or a feature?Looks fine?! Isn't foo1 == foo2 what you want?
Oct 01 2010
Trass3r <un known.com> wrote:He mentioned that the code asserts. I say this is fishy, but I don't know if it should assert or not. -- Simenvoid main() { Baz baz = new Baz(); Bar bar = baz; Foo foo1 = bar; Foo foo2 = baz; assert(foo1 is foo2); } foo1 and foo2 have the same type and point to the same object. Yet they have different addresses. Is it a bug, or a feature?Looks fine?! Isn't foo1 == foo2 what you want?
Oct 01 2010
On Fri, 01 Oct 2010 19:36:11 +0400, Trass3r <un known.com> wrote:Sadly, opEquals is only defined for Objects, not interfaces: Error: function object.opEquals (Object lhs, Object rhs) is not callable using argument types (Foo,Foo) Besides, I put `is' on purpose. With that assertion I make sure that references are *same*, not that they are equal.void main() { Baz baz = new Baz(); Bar bar = baz; Foo foo1 = bar; Foo foo2 = baz; assert(foo1 is foo2); } foo1 and foo2 have the same type and point to the same object. Yet they have different addresses. Is it a bug, or a feature?Looks fine?! Isn't foo1 == foo2 what you want?
Oct 01 2010
On Fri, 01 Oct 2010 04:32:24 -0400, Denis Koroskin <2korden gmail.com> wrote:I always thought that in D interface inheritance is always virtual, i.e. you only inherit it once even if it is specified twice (or more) within hierarchy. Until I got an assertion on the following test (reduced from a real example): interface Foo { } class Bar : Foo { } class Baz : Bar, Foo { } void main() { Baz baz = new Baz(); Bar bar = baz; Foo foo1 = bar; Foo foo2 = baz; assert(foo1 is foo2); } foo1 and foo2 have the same type and point to the same object. Yet they have different addresses. Is it a bug, or a feature? (http://ideone.com/MnnL8 virtual inheritance used, fails otherwise, of course).I agree, I think you should file a bug on this. -Steve
Oct 04 2010
On Mon, 04 Oct 2010 15:39:46 +0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:On Fri, 01 Oct 2010 04:32:24 -0400, Denis Koroskin <2korden gmail.com> wrote:Already done: http://d.puremagic.com/issues/show_bug.cgi?id=4979I always thought that in D interface inheritance is always virtual, i.e. you only inherit it once even if it is specified twice (or more) within hierarchy. Until I got an assertion on the following test (reduced from a real example): interface Foo { } class Bar : Foo { } class Baz : Bar, Foo { } void main() { Baz baz = new Baz(); Bar bar = baz; Foo foo1 = bar; Foo foo2 = baz; assert(foo1 is foo2); } foo1 and foo2 have the same type and point to the same object. Yet they have different addresses. Is it a bug, or a feature? (http://ideone.com/MnnL8 virtual inheritance used, fails otherwise, of course).I agree, I think you should file a bug on this. -Steve
Oct 04 2010