[Mono-bugs] [Bug 31835][Nor] New - incorrect opcodes when assigning enum value to System.Enum

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
6 Oct 2002 18:37:22 -0000


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 hwang_rob@yahoo.ca.

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

--- shadow/31835	Sun Oct  6 14:37:22 2002
+++ shadow/31835.tmp.6046	Sun Oct  6 14:37:22 2002
@@ -0,0 +1,89 @@
+Bug#: 31835
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: hwang_rob@yahoo.ca               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: incorrect opcodes when assigning enum value to System.Enum
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+If you define a enum type and then assign a value of that enum to
+System.Enum, you get some opcodes that cause a segfault in the runtime.
+
+According to the C# spec, all enumeration types are derived
+from System.Enum.  The value of an enum member v declared
+in enum type E is (E)v.
+
+NB System.Enum is derived from ValueType but is not a value type
+and furthermore is a class, not an enumeration itself (MSDN docs).  
+Therefore it seems that something like Enum test = FlagEnum.b; is 
+legal and can be performed without any explicit conversion.
+However, the C# spec is silent about this when it discusses implicit 
+conversions.
+ 
+
+Steps to reproduce the problem:
+1. Here's a test case, although EnumTest.cs from the NUnit test cases will
+cause this as well.
+
+using System;
+public class A {
+        enum FlagEnum {a,b,c};
+        public static void Main() {
+
+                Enum test = FlagEnum.b;
+                Console.WriteLine( "{0}", test.ToString() );
+        }
+}
+
+
+Actual Results:
+
+Currently, mcs compiles this as follows and results in a 
+segfault when you run it with mono:
+
+        .locals init (
+                class [corlib]System.Enum       V_0)
+        IL_0000: ldc.i4.1 
+        IL_0001: stloc.0 
+        IL_0002: ldstr "{0}"
+        IL_0007: ldloc.0 
+        IL_0008: callvirt instance string class [corlib]System.Enum::ToString()
+        IL_000d: call void class [corlib]System.Console::WriteLine(string,
+object)
+        IL_0012: ret 
+
+
+
+Expected Results:
+
+Good question.  You could make an argument that mcs should issue an error,
+but I don't believe this is the correct behaviour.  I think it should box
+the enum value before doing the assignment.  This seems to be what csc
+does, and furthermore makes the NUnit test case EnumTest.cs a lot happier.
+
+Either way, this is a bug in mcs.
+
+How often does this happen? 
+
+Always.
+
+Additional Information:
+
+I'll attach a possible patch to ConvertImplicitStandard and
+StandardConversionExists in ecore.cs.  Not sure if this is the correct
+place to put them; I suppose you could make an argument for putting it in
+ImplicitReferenceConversion....