[Mono-bugs] [Bug 68711][Nor] New - implicit casts not transitive

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 23 Oct 2004 03:07:02 -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 dan@clevermachine.com.

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

--- shadow/68711	2004-10-23 03:07:02.000000000 -0400
+++ shadow/68711.tmp.26763	2004-10-23 03:07:02.000000000 -0400
@@ -0,0 +1,84 @@
+Bug#: 68711
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: dan@clevermachine.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: implicit casts not transitive
+
+Description of Problem:
+
+If I define a class C with an implicit operator to convert type X to type
+C, and type Y can implicitly cast to type X, attempting to implicitly cast
+X to C generates a compiler error.  The following code, which demonstrates
+this, compiles with csc.exe, but generates an error with mcs.
+
+
+Steps to reproduce the problem:
+
+The following code illustrates the problem:
+
+using System;
+class SuperDecimal{
+   private Decimal val;
+
+   public SuperDecimal( Decimal val )
+   {
+      this.val = val;
+   }
+
+   public static implicit operator SuperDecimal(decimal val)
+   {
+      return new SuperDecimal( val );
+   }
+
+   public static void Main()
+   {
+      int i = 2;
+      SuperDecimal sd = i;
+   }
+}
+
+
+Actual Results:
+
+mcs issues the following error:
+test.cs(18) error CS0029: Cannot convert implicitly from `int' to
+`SuperDecimal'Compilation failed: 1 error(s), 0 warnings
+
+
+Expected Results:
+csc.exe compiles the code, and it runs as expected
+
+How often does this happen? 
+Every time
+
+Additional Information:
+
+mcs info: Mono C# compiler version 1.0.2.0 running on Debian unstable on
+i386 Linux
+
+csc.exe is running on Windows Server 2003 using the .NET Framework v1.1.4322
+
+It may be helpful to note that when I change this line:
+      SuperDecimal sd = i;
+to:
+      SuperDecimal sd = (SuperDecimal)i;
+
+mcs outputs this:
+
+test.cs(18) error CS0030: Cannot convert type 'int' to 'decimal'
+test.cs(18) error CS0030: Cannot convert type 'int' to 'SuperDecimal'
+Compilation failed: 2 error(s), 0 warnings
+
+Let me know if I can provide more info.  Thanks!