[Mono-bugs] [Bug 74481][Cri] New - Comparing against null

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 7 Apr 2005 05:29:26 -0400 (EDT)


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 joe@otee.dk.

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

--- shadow/74481	2005-04-07 05:29:26.000000000 -0400
+++ shadow/74481.tmp.6697	2005-04-07 05:29:26.000000000 -0400
@@ -0,0 +1,67 @@
+Bug#: 74481
+Product: Mono: Compilers
+Version: 1.0
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Critical
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: joe@otee.dk               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Comparing against null
+
+When comparing an existing instance against null the overloaded operator is never called.
+This used to work in mono 1.0.4 for sure. But doesn't work on mono 1.1.6
+I haven't used any other mono releases in between so i don't know when it broke
+
+using System;
+
+public class Test
+{
+	static public bool operator == (Test x, Test y)
+	{
+		System.Console.WriteLine ("The operator == is being called");
+		return false;
+	}
+
+	static public bool operator != (Test x, Test y)
+	{
+		System.Console.WriteLine ("The operator != is being called");
+		return true;
+	}
+	
+	public override bool Equals (object o)
+	{
+		System.Console.WriteLine ("Equals function is being called");
+		return false;
+	}
+
+	public override int GetHashCode ()
+	{
+		System.Console.WriteLine ("Hash function is being called");
+		return 0;
+	}
+	
+};
+
+public class Bug
+{
+  static void Main(string[] args)
+  {
+    Test t = new Test ();
+    if (t == null)
+    {
+		System.Console.WriteLine ("The operator correctly returned false");
+    }
+    else
+    {
+   		System.Console.WriteLine ("The operator is never called");
+    }
+  }
+}