[Mono-bugs] [Bug 21072] Changed - Crash compiling a constant variable of Enum type

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
28 Feb 2002 21:38:28 -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 f_ai@hotmail.com.

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

--- shadow/21072	Tue Feb 26 19:56:16 2002
+++ shadow/21072.tmp.2189	Thu Feb 28 16:38:28 2002
@@ -48,6 +48,46 @@
 
 We will be able to work around this on our implementation of
 System.Reflection, but I can not figure out how to get this to work
 with .NET.
 
 I have included a descriptive message about this in the compiler now.
+
+------- Additional Comments From f_ai@hotmail.com  2002-02-28 16:38 -------
+I discovered something interesting related to this problem.
+On 'Enum.DefineEnum' the type that is actually been registered in 
+the type manager as the enum type, is not actually the type of the 
+enum, but a 'TypeBuilder' "RootContext.TypeManager.AddEnumType 
+(Name, TypeBuilder, this)". 
+
+This has to be done this way, because the type is under construction 
+( adding the enum literals-values ), after the type is 
+created 'TypeBuilder.CreateType' all the calls that modify the type 
+fail.
+
+The 'Const' class have a member 'type' representing the 'Type' of 
+the constant to be created, but at this point, the type of the enum 
+is not been created yet, what we think is UserDefinedEnumType is 
+actually a TypeBuilder for the UserDefinedEnumType. This is why 
+System.Enum.ToObject fails.
+
+If we create the real type:
+
+if (type is TypeBuilder)
+   type = ((TypeBuilder)type).CreateType();
+
+before the type is used in 'Const.LookupConstantValue' the routine 
+succeeds to return the constant value.
+
+I'm not sure if it is too late to change the type information in the 
+type manager ( replace the type-builder by the real-type) after this 
+type is created, in order to speed things up for other resolves.
+
+I'm fearly new to the .NET framework, and really new to 'Emit, 
+Refection ,...'. I tried creating the enum using EnumBuilder and not 
+TypeBuilder, change the defines of the type and the literals, and 
+the code looked simpler that way ( i did not actualy finish the 
+code, just comments here and there, and some code on top of 
+that !!!). The only issue that i can see, is for nested enums, the 
+parent_builder is not a 'ModuleBuilder' but a 'Typebuilder'.
+Why did you choose to implement the enum type with a 'TypeBuiler' 
+and not an EnumBuilder ?