[Mono-bugs] [Bug 81007][Nor] New - EnumBuilder emits literals with the integral type

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Mar 2 13:36:44 EST 2007


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 rolfkvinge at ya.com.

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

--- shadow/81007	2007-03-02 13:36:44.000000000 -0500
+++ shadow/81007.tmp.15731	2007-03-02 13:36:44.000000000 -0500
@@ -0,0 +1,75 @@
+Bug#: 81007
+Product: Mono: Class Libraries
+Version: 1.0
+OS: other
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: rolfkvinge at ya.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: EnumBuilder emits literals with the integral type
+
+MS' EnumBuilder (and TypeBuilder when used to emit enums) changes the type 
+of the literal to the type of the enum, while Mono emits the literal with 
+the base integral type.
+
+Test code:
+
+using System;
+using System.Collections;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Text;
+
+class vbnc_bugs
+{
+	static void Main ()
+	{
+		AssemblyBuilderAccess access = 
+AssemblyBuilderAccess.RunAndSave;
+		TypeAttributes attribs = TypeAttributes.Public;
+
+		AssemblyName name = new AssemblyName ("a");
+		AssemblyBuilder assembly = 
+AppDomain.CurrentDomain.DefineDynamicAssembly (name, access);
+
+		ModuleBuilder module = assembly.DefineDynamicModule ("m", 
+"test.dll");
+
+		EnumBuilder e = module.DefineEnum ("E", attribs, typeof 
+(int));
+		FieldBuilder field;
+		if (typeof(int).GetType ().Name == "RuntimeType") {
+			field = e.DefineLiteral ("A", 1);
+		} else {
+			object o = Enum.ToObject (e, 1);
+			Console.WriteLine ("Mono workaround, type = " + 
+o.GetType().Name);
+			field = e.DefineLiteral ("A", o);
+		}
+		Type en = e.CreateType ();
+		
+		if (typeof (int) == field.FieldType) {
+			Console.WriteLine ("FAILED 1 (field.FieldType=" + 
+field.FieldType.Name + ", should be " + e.Name + ")");
+		} else {
+			Console.WriteLine ("SUCCESS 1");
+		}
+		
+		FieldInfo f = en.GetField ("A");
+
+		if (typeof (int) == f.FieldType) {
+			Console.WriteLine ("FAILED 2 (field.FieldType=" + 
+f.FieldType.Name + ", should be " + en.Name + ")");
+		} else {
+			Console.WriteLine ("SUCCESS 2");
+		}
+	}
+}


More information about the mono-bugs mailing list