digitalmars.D.bugs - [Issue 7470] New: opEquals for interfaces
- d-bugmail puremagic.com (43/43) Feb 08 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7470
- d-bugmail puremagic.com (30/30) Feb 09 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7470
http://d.puremagic.com/issues/show_bug.cgi?id=7470
Summary: opEquals for interfaces
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: dawg dawgfoto.de
interface I
{
int value();
equals_t opEquals(I other);
// final opEquals should be allowed too
// final equals_t opEquals(I other) { return value() == other.value(); }
}
class A : I
{
override int value() { return 0; }
override equals_t opEquals(I other) { return value() == other.value(); }
}
class B : I
{
override int value() { return 0; }
override equals_t opEquals(I other) { return value() == other.value(); }
}
void main()
{
I i1 = new A, i2 = new B;
assert(i1 == i2);
}
----
I think this was the actual issue that Steven filed under bug 4088.
Using explicit casts solved compiler generated interface comparison,
but doesn't allow a real opEquals for interfaces.
Note that opCmp works as expected.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 08 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7470
Steven Schveighoffer <schveiguy yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |schveiguy yahoo.com
07:36:48 PST ---
The original test case was that I could not compare two interfaces in the way
you say, yes. But you can compare two interfaces via Object:
interface I
{
}
class C : I
{
}
void main()
{
I i1 = new C, i2 = new C;
assert(i1 == i2); // should work now, did not work before
}
Prior to the fix, you could not compare two interfaces under *any
circumstances*. This at least allows interfaces to pull in Object's method for
opEquals.
What you are asking for is for interfaces (and by extension objects) to be
comparable to other objects using a derived type, which I think could be a
useful addition, but complex in implementation. You don't want to get into a
situation where two objects compare differently depending on the static type
used.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 09 2012








d-bugmail puremagic.com