www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Cannot compare shared Objects

reply Jacob Carlborg <doob me.com> writes:
The following example doesn't compile with D2:

class Foo
{
     private Object value;

     synchronized bool hasValue (Object val)
     {
         return value == val;
     }
}

It gives the error:

main.d(11): Error: function object.opEquals (Object lhs, Object rhs) is 
not callable using argument types (shared(Object),Object)
main.d(11): Error: cannot implicitly convert expression (this.value) of 
type shared(Object) to object.Object

Is that because object.opEquals hasn't been overloaded with a shared 
version yet? If that's the case has this already been reported in bugzilla?

-- 
/Jacob Carlborg
Sep 12 2010
next sibling parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Jacob Carlborg <doob me.com> wrote:

 The following example doesn't compile with D2:

 class Foo
 {
      private Object value;

      synchronized bool hasValue (Object val)
      {
          return value == val;
      }
 }

 It gives the error:

 main.d(11): Error: function object.opEquals (Object lhs, Object rhs) is  
 not callable using argument types (shared(Object),Object)
 main.d(11): Error: cannot implicitly convert expression (this.value) of  
 type shared(Object) to object.Object

 Is that because object.opEquals hasn't been overloaded with a shared  
 version yet? If that's the case has this already been reported in  
 bugzilla?

You're absolutely right about the cause. This is related to, though not the same issue as, #1824 (http://d.puremagic.com/issues/show_bug.cgi?id=1824) I'm unsure whether this should be added to #1824 or filed as a separate bug. -- Simen
Sep 12 2010
parent Jacob Carlborg <doob me.com> writes:
On 2010-09-12 23:00, Simen kjaeraas wrote:
 Jacob Carlborg <doob me.com> wrote:

 The following example doesn't compile with D2:

 class Foo
 {
 private Object value;

 synchronized bool hasValue (Object val)
 {
 return value == val;
 }
 }

 It gives the error:

 main.d(11): Error: function object.opEquals (Object lhs, Object rhs)
 is not callable using argument types (shared(Object),Object)
 main.d(11): Error: cannot implicitly convert expression (this.value)
 of type shared(Object) to object.Object

 Is that because object.opEquals hasn't been overloaded with a shared
 version yet? If that's the case has this already been reported in
 bugzilla?

You're absolutely right about the cause. This is related to, though not the same issue as, #1824 (http://d.puremagic.com/issues/show_bug.cgi?id=1824) I'm unsure whether this should be added to #1824 or filed as a separate bug.

Filed as http://d.puremagic.com/issues/show_bug.cgi?id=4857 -- /Jacob Carlborg
Sep 13 2010
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Sun, 12 Sep 2010 17:00:54 -0400, Simen kjaeraas  
<simen.kjaras gmail.com> wrote:

 Jacob Carlborg <doob me.com> wrote:

 The following example doesn't compile with D2:

 class Foo
 {
      private Object value;

      synchronized bool hasValue (Object val)
      {
          return value == val;
      }
 }

 It gives the error:

 main.d(11): Error: function object.opEquals (Object lhs, Object rhs) is  
 not callable using argument types (shared(Object),Object)
 main.d(11): Error: cannot implicitly convert expression (this.value) of  
 type shared(Object) to object.Object

 Is that because object.opEquals hasn't been overloaded with a shared  
 version yet? If that's the case has this already been reported in  
 bugzilla?

You're absolutely right about the cause. This is related to, though not the same issue as, #1824 (http://d.puremagic.com/issues/show_bug.cgi?id=1824) I'm unsure whether this should be added to #1824 or filed as a separate bug.

Not exactly right. Comparing two objects has been altered significantly since a few versions ago. Instead of a = b translating to a.opEquals(b), it translates to opEquals(a, b). opEquals(a, b) is defined in object.di as: bool opEquals(Object o1, Object o2); This means you cannot compare shared, immutable, or const objects, and you cannot compare interfaces (because interfaces do not implicitly cast to Object). Even if you updated Object.opEquals, it still wouldn't work. It is a severe problem that has been ignored for quite a while (especially the interface comparison problem). The interface bug report: http://d.puremagic.com/issues/show_bug.cgi?id=4088 -Steve
Sep 13 2010