[Mono-bugs] [Bug 78079][Wis] New - CS0019 with operator== where implicit conversion exists

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Apr 11 13:48:51 EDT 2006


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 ewtewuo02 at sneakemail.com.

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

--- shadow/78079	2006-04-11 13:48:51.000000000 -0400
+++ shadow/78079.tmp.27941	2006-04-11 13:48:51.000000000 -0400
@@ -0,0 +1,54 @@
+Bug#: 78079
+Product: Mono: Compilers
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: ewtewuo02 at sneakemail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: CS0019 with operator== where implicit conversion exists
+
+Compile the following code:
+
+using System;
+namespace Bug {
+  class FakeInt {
+    private long _value;
+    public FakeInt(long val) {
+      _value = val;
+    }
+    public static implicit operator long(FakeInt self) {
+      return self._value;
+    }
+  }
+  class MainClass {
+    public static void Main() {
+      FakeInt fi = new FakeInt(42);
+      long li = 0;
+      if( fi == 42 ) {
+        Console.WriteLine("Okay");
+      }
+      else {
+        Console.WriteLine("Huh??");
+      }
+    }
+  }
+}
+
+mcs and gcms from release 1.1.13.2 as well as both from SVN (version 58387)
+all report 
+
+    operator-bug.cs(16,11): error CS0019: Operator `==' cannot be applied
+to operands of type `Bug.FakeInt' and `int'
+
+I expected that the implicit operator would be used to promote the FakeInt
+to long, which could then be compared to an int.  And using Microsoft
+Visual C# 2005, the code compiles and runs as I expected.


More information about the mono-bugs mailing list