The nested in type should not be inflated.
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 5 Oct 2010 19:23:56 +0000 (16:23 -0300)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 5 Oct 2010 19:23:56 +0000 (16:23 -0300)
* class.c (mono_generic_class_get_class): Don't inflated
nested_in since it's not the expected behavior from managed
land. It's a safety issue as well since the outer type can
have more generic arguments.

* TypeTest.cs: Add regression test.

Fixes #643890

mcs/class/corlib/Test/System/TypeTest.cs
mono/metadata/class.c

index 6afd86d82d8c74cd679dbddaccde0642b9209375..e652e4276ff2525b87ba4dac782fab4b92037de1 100644 (file)
@@ -168,6 +168,8 @@ namespace MonoTests.System
                {
                        return a;
                }
+               
+               public class Nested<K> {}
        }
        
        class Foo<T, U>
@@ -3338,6 +3340,13 @@ PublicKeyToken=b77a5c561934e089"));
                } catch (TypeLoadException) { }
 
                }
+               
+               [Test] //Bug643890
+               public void DeclaringTypeOfGenericNestedTypeInstanceIsOpen ()
+               {
+                       var type = typeof (Foo<int>.Nested<string>);
+                       Assert.AreSame (typeof (Foo<>), a.DeclaringType, "#1");
+               }
 
 #if NET_4_0
                interface IGetInterfaceMap<in T>
index 170f844a87ae29db619736e848e64a2911f0c325..d4f0a8ecb67117a10531008a15e2d0d1eff9fe8f 100644 (file)
@@ -5311,13 +5311,8 @@ mono_generic_class_get_class (MonoGenericClass *gclass)
        gklass = gclass->container_class;
 
        if (gklass->nested_in) {
-               /* 
-                * FIXME: the nested type context should include everything the
-                * nesting context should have, but it may also have additional
-                * generic parameters...
-                */
-               klass->nested_in = mono_class_inflate_generic_class (gklass->nested_in,
-                                                                                                                        mono_generic_class_get_context (gclass));
+               /* The nested_in type should not be inflated since it's possible to produce a nested type with less generic arguments*/
+               klass->nested_in = gklass->nested_in;
        }
 
        klass->name = gklass->name;