OpEquals and Interfaces

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 13 16:13:31 PDT 2010


On Tue, 13 Apr 2010 18:04:04 -0400, Ali Çehreli <acehreli at yahoo.com> wrote:

> Christoph Mueller is asking the exact problem that I've been having. :)
>
> Steven Schveighoffer wrote:
>
>  > If you are using D2, there is a workaround:
>  >
>  > interface I
>  > {
>  >    final bool opEquals(I other)
>  >    {
>  >       Object me = cast(Object)this;
>  >       Object they = cast(Object)other;
>  >       return equals(me, they);
>
> Is 'equals' a function on this interface?

No, it's a new global function in object.di, and it's called opEquals, not  
equals.  I guess I messed that up royally :)

Just do me == they;

That will call the function.

> But it still calls Object.opEquals:
>
> Error: function object.opEquals (Object lhs, Object rhs) is not callable  
> using argument types (I,I)

This is not Object.opEquals, it's object.opEquals -- note the  
capitalization.  The latter is a standalone function in module object.


> Error: cannot implicitly convert expression (i) of type deneme.I to  
> object.Object
> Error: cannot implicitly convert expression (i) of type deneme.I to  
> object.Object

This is a bug.  i == i should call the opEquals method on i.  Instead, the  
compiler is trying to call the standalone opEquals(Object, Object)  
function.

I confirmed with 2.043 that this is a bug.  I'll file with a test case.

-Steve




More information about the Digitalmars-d mailing list