[nem-bug] [Nemerle 0000832]: comparing structs with == raises error
feedback at nemerle.org
feedback at nemerle.org
Mon Jan 22 17:51:45 CET 2007
The following issue requires your FEEDBACK.
======================================================================
<http://nemerle.org/bugs/view.php?id=832>
======================================================================
Reported By: Luntain
Assigned To:
======================================================================
Project: Nemerle
Issue ID: 832
Category: Code Completion Engine
Reproducibility: always
Severity: minor
Priority: normal
Status: feedback
======================================================================
Date Submitted: 01-21-2007 11:19 CET
Last Modified: 01-22-2007 17:51 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.
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
======================================================================
More information about the bugs
mailing list