[nem-bug] [Nemerle 0000832]: comparing structs with == raises error
feedback at nemerle.org
feedback at nemerle.org
Fri Jan 26 19:36:01 CET 2007
The following issue has been RESOLVED.
======================================================================
<http://nemerle.org/bugs/view.php?id=832>
======================================================================
Reported By: Luntain
Assigned To: nazgul
======================================================================
Project: Nemerle
Issue ID: 832
Category: Code Completion Engine
Reproducibility: always
Severity: minor
Priority: normal
Status: resolved
Resolution: not an issue
Fixed in Version:
======================================================================
Date Submitted: 01-21-2007 11:19 CET
Last Modified: 01-26-2007 19:36 CET
======================================================================
Summary: comparing structs with == raises error
Description:
[Record] public struct Point
x: double
y: double
...
def p = Point(0,0)
def q = Point(0,0)
assert p==q //merror&http://nemerle.org/bugs/view.php?id=8592;[0m: comparing
values of types Point and Point
with reference equality
======================================================================
----------------------------------------------------------------------
nazgul - 01-22-07 17:51
----------------------------------------------------------------------
Right... you need to provide the comparison operator:
[Record]
struct P {
public x : int;
public static @== (a : P, b : P) : bool {
a.x == b.x
}
}
def a = P (1);
def b = P (1);
System.Console.WriteLine (a == b);
I don't think that any "magic" implementation of such comparison operators
would be desired (especially by default). Even if it would be done by
shallow comparison of fields - there could be still some reference fields
in given struct and comparing them by reference is quite bug prone.
Note, that .NET gives you this feature when you use Equals method:
[Record]
struct P {
public x : int;
}
def a = P (1);
def b = P (1);
System.Console.WriteLine (a.Equals (b));
and our approach is to actually forbid using ANY == unless types has
explicit == operator defined or user upcast to object.
----------------------------------------------------------------------
nazgul - 01-26-07 19:36
----------------------------------------------------------------------
By design.
Issue History
Date Modified Username Field Change
======================================================================
01-21-07 11:19 Luntain New Issue
01-22-07 17:51 nazgul Note Added: 0001631
01-22-07 17:51 nazgul Status new => feedback
01-22-07 17:51 nazgul Description Updated
01-26-07 19:36 nazgul Status feedback => resolved
01-26-07 19:36 nazgul Resolution open => not an issue
01-26-07 19:36 nazgul Assigned To => nazgul
01-26-07 19:36 nazgul Note Added: 0001645
======================================================================
More information about the bugs
mailing list