Jump to page: 1 2
Thread overview
[Issue 4088] New: opEquals not called on interfaces
Feb 14, 2011
dawg@dawgfoto.de
Feb 18, 2011
Trass3r
Feb 18, 2011
Trass3r
Jun 10, 2011
yebblies
Aug 05, 2011
Walter Bright
Aug 06, 2011
Walter Bright
Oct 15, 2011
Kenji Hara
Feb 09, 2012
Walter Bright
Feb 09, 2012
dawg@dawgfoto.de
Feb 09, 2012
Walter Bright
Feb 09, 2012
Walter Bright
Feb 09, 2012
Walter Bright
Feb 09, 2012
dawg@dawgfoto.de
Feb 09, 2012
Walter Bright
April 13, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4088

           Summary: opEquals not called on interfaces
           Product: D
           Version: 2.041
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: schveiguy@yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy@yahoo.com> 2010-04-13 16:33:39 PDT ---
Given an interface that defines opEquals, the compiler will prefer to call the object.opEquals(Object, Object) on it.  However, interfaces don't implicitly cast to Objects thanks to COM.

example:

interface I
{
    bool opEquals(I other);
}

bool foo(I i1, I i2)
{
    return i1 == i2;
}

testopequals.d(8): Error: function object.opEquals (Object lhs, Object rhs) is
not callable using argument types (I,I)
testopequals.d(8): Error: cannot implicitly convert expression (i1) of type
testopequals.I to object.Object
testopequals.d(8): Error: cannot implicitly convert expression (i2) of type
testopequals.I to object.Object

And can someone add 2.042 and 2.043 to the version list? This is tested on 2.043.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4088



--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> 2010-05-19 15:27:58 PDT ---
Note, this is a problem for dcollections 2.0:

http://www.dsource.org/projects/dcollections/ticket/4

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 14, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4088



--- Comment #2 from dawg@dawgfoto.de 2011-02-13 16:49:22 PST ---
Created an attachment (id=907)
Proposed fix

It is actually a very surprising bug, that interfaces can't be compared as it
might break structs due to the compiler generated opEquals.
The attached patch does an explicit cast to Object.
This would still not work with C++/COM interfaces.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 18, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4088


Trass3r <mrmocool@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool@gmx.de


--- Comment #3 from Trass3r <mrmocool@gmx.de> 2011-02-18 05:54:06 PST ---
Can't dmd just check the "type" of a given interface and only allow implicit casts to Object if it is a normal one, i.e. no COM and no C++ interface?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 18, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4088



--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-02-18 08:33:19 PST ---
(In reply to comment #3)
> Can't dmd just check the "type" of a given interface and only allow implicit casts to Object if it is a normal one, i.e. no COM and no C++ interface?

I'm not familiar with the internals of the compiler, but I believe this is true.  I think it should be statically verifiable that an interface is a COM interface, and then opEquals can be handled differently.

However, we continue to get silence from Walter on this...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 18, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4088


Trass3r <mrmocool@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid


--- Comment #5 from Trass3r <mrmocool@gmx.de> 2011-02-18 15:51:23 PST ---
I think this should be tackled at a deeper level, probably somewhere around MATCH TypeClass::implicitConvTo(Type *to) in mtype.c

to allow implicit conversions of interfaces to Object in general.

Then also this works:

void foo(Object o) {}
Interface i;

foo(i);
// or
Object o = i;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4088


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |benoit@tionex.de


--- Comment #6 from yebblies <yebblies@gmail.com> 2011-06-10 08:59:07 PDT ---
*** Issue 2794 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4088


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #7 from Walter Bright <bugzilla@digitalmars.com> 2011-08-05 16:25:25 PDT ---
I'm not at all sure the patch is the right solution to this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4088



--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> 2011-08-05 20:34:51 PDT ---
Issues that need to be resolved:

1. what should happen if this is called with a COM object?

2. how does an opEquals defined in an interface interact with the object.opEquals?

3. a forced cast, unlike an implicit cast, is a blunt instrument that can do a lot more than simply cast an interface to its base class. If the arguments are other types, what are the conseqences of this forced cast?

A change of this sort needs to resolve these issues, and have test cases to verify them.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 08, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4088



--- Comment #9 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-08-08 05:47:06 PDT ---
(In reply to comment #8)
> Issues that need to be resolved:
> 
> 1. what should happen if this is called with a COM object?

Compiler error.

> 2. how does an opEquals defined in an interface interact with the object.opEquals?

If the notion of COM interfaces is specialized, then standard interfaces do not need to define opEquals, it's assumed that any standard interface (not C++ or COM) derives from Object, and implicit dynamic casting to Object to do opEquals should work.

> 3. a forced cast, unlike an implicit cast, is a blunt instrument that can do a lot more than simply cast an interface to its base class. If the arguments are other types, what are the conseqences of this forced cast?

An implicit cast to Object would be the best remedy.  However, the issue of dynamic casting and blunt casting being conflated would be a good issue to solve too.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2