[Mono-bugs] [Bug 79941][Nor] New - Explicit typecasts of enumerated values broken

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Nov 15 05:57:27 EST 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 josephg at gmail.com.

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

--- shadow/79941	2006-11-15 05:57:27.000000000 -0500
+++ shadow/79941.tmp.29556	2006-11-15 05:57:27.000000000 -0500
@@ -0,0 +1,78 @@
+Bug#: 79941
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: GNU/Linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: josephg at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Explicit typecasts of enumerated values broken
+
+Description of Problem:
+
+Doing an explicit typecast of an enum value causes a compiler error,
+despite any combination of implicit and explicit conversion operations defined.
+
+Note that implicit conversions of enums work.
+
+Steps to reproduce the problem:
+namespace Test
+{
+    public class Foo
+    {
+        public Foo()
+        {}
+
+        public static explicit operator Foo(Bar the_bar)
+        {
+            return new Foo();
+        }
+        public static implicit operator Foo(Bar the_bar)
+        {
+            return new Foo();
+        }
+    }
+
+    public enum Bar
+    {
+        ABar
+    }
+
+    public class Tester
+    {
+        public static void Main()
+        {
+            Foo f1 = Bar.ABar;        // OK
+            Foo f2 = (Foo) Bar.ABar;  // Compile error
+        }
+    }
+}
+
+
+Actual Results:
+$ mcs typecast.cs -t:library
+typecast.cs(30,14): error CS0030: Cannot convert type `Test.Bar' to `Test.Foo'
+
+
+Expected Results:
+Successful compilation
+
+
+Additional Information:
+ $ mcs --version
+Mono C# compiler version 1.2.0.0
+
+It is unknown whether this bug exists in Mono 1.1
+
+This bug has been marked as normal priority (rather than minor) as there
+are times when explicit conversions are needed (such as explicitly choosing
+from overloaded functions). In these circumstances a workaround is much
+more complex than merely moving to implicit conversion operators.


More information about the mono-bugs mailing list