Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 0.4
-
Fix Version/s: 0.6
-
Component/s: Runtime (Boo.Lang)
-
Labels:None
-
Number of attachments :
Description
Overriding the Equals method allows you to use == to test for equality but its not commutative. Would it make sense in runtime method op_Equality to "return lhs.Equals(rhs) || rhs.Equals(lhs);"
class Test:
public x as double
def Equals(y as object) as bool:
return cast(double, y) == x
o1 as object = 1.0
o2 as object = 1
d1 as duck = 1.0
d2 as duck = 1
t1 = Test(x: 1)
assert o1 == 1
assert 1 == o1
assert o1 == o2
assert o2 == o1
assert d1 == 1
assert 1 == d1
assert d1 == d2
assert d2 == d1
assert o1 = d2
assert d2 = o1
assert t1 == o2
assert o2 == t1 // fails
This 15 character patch makes op_Equality commuative, mimicking C#'s Equals() overloadingness.
(Tortise SVN had a fit and demands stuffing the entire file into the .patch.)