[Mono-bugs] [Bug 74684][Wis] New - Unable to define generic field inside generic type through S.R.E

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 21 Apr 2005 08:14:04 -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 nazgul@omega.pl.

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

--- shadow/74684	2005-04-21 08:14:04.000000000 -0400
+++ shadow/74684.tmp.19477	2005-04-21 08:14:04.000000000 -0400
@@ -0,0 +1,82 @@
+Bug#: 74684
+Product: Mono: Class Libraries
+Version: 1.0
+OS: 
+OS Details: mono svn from 20 Apr 2005
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: nazgul@omega.pl               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Unable to define generic field inside generic type through S.R.E
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+There is an assertion in runtime when I try to generate code similar to
+class A <T> {
+  A <T> f;
+}
+
+using S.R.E.
+
+Steps to reproduce the problem:
+1. Compile and run following program (using gmcs)
+
+using System.Reflection;
+using System.Reflection.Emit;
+
+class Program
+{
+static void Main(string[] args)
+{
+  AssemblyName name = new AssemblyName();
+  name.Name = "o";
+  AssemblyBuilder builder =
+AppDomain.CurrentDomain.DefineDynamicAssembly(name,
+AssemblyBuilderAccess.RunAndSave);
+  ModuleBuilder mb = builder.DefineDynamicModule("out", "bla.dll");
+  TypeBuilder tb = mb.DefineType("MyGenericClass");
+  GenericTypeParameterBuilder[] gtbs = tb.DefineGenericParameters("'a");
+
+  Type inst = tb.GetGenericTypeDefinition ().BindGenericParameters (new
+Type[] { gtbs [0] });
+
+  FieldBuilder metb = tb.DefineField("foo", inst, FieldAttributes.Public);
+  
+  tb.CreateType();
+  builder.Save("bla.dll");
+ }
+}
+
+
+Actual Results:
+** ERROR **: file metadata.c: line 2739 (mono_type_size): assertion failed:
+(!gclass->inst->is_open && !gclass->klass->generic_container)
+aborting...
+Aborted
+
+
+Expected Results:
+Clear run
+
+How often does this happen? 
+Always
+
+Additional Information:
+Obviously gmcs is able to generate mentioned code, so it must be using a
+little bit different algorithm for creating field.
+But above way seems completely valid and works on MS.NET Beta1 
+(after tweaking 
+Type inst = tb.GetGenericTypeDefinition ().BindGenericParameters (new
+Type[] { gtbs [0] });
+to 
+Type inst = tb.BindGenericParameters (new Type[] { gtbs [0] });
+
+which is their bug and I guess it's fixed in Beta2)