[Mono-bugs] [Bug 75448][Wis] New - generics c#2.0

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Jul 2 21:27:30 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by john.caloyannis at gmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=75448

--- shadow/75448	2005-07-02 21:27:30.000000000 -0400
+++ shadow/75448.tmp.5838	2005-07-02 21:27:30.000000000 -0400
@@ -0,0 +1,103 @@
+Bug#: 75448
+Product: Mono: Compilers
+Version: 1.1
+OS: 
+OS Details: Ubuntu Hoary 5.0.4
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: john.caloyannis at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: generics c#2.0
+
+I'm not quite sure this is bug since the generics are not yet very
+precisely defined. I have not tried on a windows machine yet.
+Am using mono 1.1.8.1.
+
+The symptom is the following:
+Assume we have a class parametrized by some type T in which we have
+overridden the == operator.
+When using the == in the class between objects of type T I think it should
+use the overridden == operator. I am however not quite sure about it. Any
+comment would be welcome.
+Here is a small program ready to run which shows that the behavior is not
+the expected one.
+
+// vim:sw=4:ts=8
+using System;
+
+namespace T
+{
+    public class TestClass<T>
+    {
+	public TestClass(T x) { _x = x; }
+	public bool Check (T y) { return y == _x; }
+	private T _x;
+    }
+
+    public class SomeClass
+    {
+	public SomeClass () : this (0, "") {}
+	public SomeClass (int n, String s) { _n = n; _s = s; }
+	public int n { get {return _n;} set {_n = value;} }
+	public String s { get {return _s;} set {_s = value;} }
+	public static bool operator == (SomeClass left, SomeClass right)
+	{
+	    System.Console.WriteLine ("in == operator");
+	    return ((left.n % 2) == (right.n % 2)) && (left.s.Equals (right.s));
+	}
+	public static bool operator != (SomeClass left, SomeClass right)
+	{
+	    return ((left.n % 2) != (right.n % 2)) || (!left.s.Equals (right.s));
+	}
+	public override bool Equals (Object o)
+	{
+	        System.Console.WriteLine ("in Equals");
+		if (o == null) { return false; }
+		if (! (o is SomeClass)) { return false; }
+		return (SomeClass) o == this;
+	}
+	public override int GetHashCode () { return _n + _s.GetHashCode (); }
+
+	private int _n;
+	private String _s;
+    }
+
+    public class Test
+    {
+	public static void Main()
+	{
+	    SomeClass t1, t2;
+	    TestClass<SomeClass> a;
+
+	    t1 = new SomeClass (12, "str");
+	    t2 = new SomeClass (4, "str");
+	    if (t1 == t2) {
+		System.Console.WriteLine ("equal");
+	    } else {
+		System.Console.WriteLine ("! equal");
+	    }
+	    a = new TestClass<SomeClass>(t1);
+	    if (a.Check (t2)) {
+		System.Console.WriteLine ("checks");
+	    } else {
+		System.Console.WriteLine ("! checks");
+	    }
+	}
+    }
+}
+compile the above: gmcs Test.cs
+run it: mono Test.exe
+
+you get
+in == operator
+equal
+! checks
+
+showing that the Check operation does not use the == operator of SomeClass.


More information about the mono-bugs mailing list