Fix #642130.
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 4 Oct 2010 18:54:10 +0000 (15:54 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 4 Oct 2010 18:58:22 +0000 (15:58 -0300)
* MonoGenericClass.cs (.ctor): Only register with the runtime
when the underlying TB is not finished.

* MonoGenericClassTest.cs: Add regression test.

* TypeTest.cs: Fix a test that had a broken assumption.

Fix #642130

mcs/class/corlib/System.Reflection/MonoGenericClass.cs
mcs/class/corlib/Test/System.Reflection/MonoGenericClassTest.cs
mcs/class/corlib/Test/System/TypeTest.cs

index 5bace9415d48a1ba9bee245e3f7014f9d7eb5d9a..fcdd71f72251e3acd0001785cc208708c102951a 100644 (file)
@@ -71,7 +71,17 @@ namespace System.Reflection
                {
                        this.generic_type = tb;
                        this.type_arguments = args;
-                       register_with_runtime (this); /*Temporary hack while*/
+                       /*
+                       This is a temporary hack until we can fix the rest of the runtime
+                       to properly handle this class to be a complete UT.
+
+                       We must not regisrer this with the runtime after the type is created
+                       otherwise created_type.MakeGenericType will return an instance of MonoGenericClass,
+                       which is very very broken.
+                       */
+                       if (tb is TypeBuilder && !(tb as TypeBuilder).is_created)
+                               register_with_runtime (this);
+                       
                }
 
 
index 17b1b2896cc991a074685315ce524e14afd56eac..9116054f10c16683ef6ddf2a9d68be7545bda5ef 100644 (file)
@@ -186,6 +186,24 @@ namespace MonoTests.System.Reflection.Emit
                                Assert.Fail ("#13");
                        } catch (NotSupportedException) {  }
                }
+
+               [Test]
+               public void ClassMustNotBeRegisteredAfterTypeBuilderIsFinished ()
+               {
+                       TypeBuilder tb = module.DefineType ("foo.type");
+                       tb.DefineGenericParameters ("T");
+
+                       var c = tb.CreateType ();
+
+                       var sreInst = tb.MakeGenericType (typeof (int));
+                       var rtInst = c.MakeGenericType (typeof (int));
+
+                       Assert.AreNotSame (sreInst, rtInst, "#1");
+
+                       /*This must not throw*/
+                       rtInst.IsDefined (typeof (int), true);
+               }
        }
+
 #endif
 }
index 518c01eadcfdc7e8121036d3be131a77099570c4..6afd86d82d8c74cd679dbddaccde0642b9209375 100644 (file)
@@ -2961,13 +2961,11 @@ PublicKeyToken=b77a5c561934e089"));
                public void MakeGenericType_BadUserType ()
                {
                        Type ut = new UserType (null);
-                       try {
-                               Type t = typeof (Foo<>).MakeGenericType (ut);
-                               Assert.Fail ("#1");
-                       } catch (ArgumentException) {
-                       }
+                       Type t = typeof (Foo<>).MakeGenericType (ut);
+                       var g0 = t.GetGenericArguments () [0];
+                       Assert.AreSame (g0, ut, "#1");
                }
-       
+
                [Test]
                public void MakeGenericType_WrongNumOfArguments ()
                {