[reflection] Test case for 36305.
authorAleksey Kliger <aleksey@xamarin.com>
Wed, 9 Dec 2015 15:30:38 +0000 (10:30 -0500)
committerAleksey Kliger <aleksey@xamarin.com>
Wed, 9 Dec 2015 15:39:28 +0000 (10:39 -0500)
When the base type of a generic type is an open constructed generic
type, GetBaseDefinition() must take the instantiation into account while
traversing the class hierarchy.

mcs/class/corlib/Test/System.Reflection/MethodInfoTest.cs

index 57e2fa6364e557041f8fd5e816e6fb80957620cc..71119b1673a7308b2bc7bf692771aad259bfdca3 100644 (file)
@@ -3,9 +3,11 @@
 //
 // Authors:
 //  Zoltan Varga (vargaz@gmail.com)
+//  Aleksey Kliger (aleksey@xamarin.com)
 //
 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2015 Xamarin, Inc. (http://www.xamarin.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -293,6 +295,35 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (typeof (GBD_D), typeof (GBD_E).GetMethod ("f").GetBaseDefinition ().DeclaringType);
                }
 
+               class GenericBase<T,H> {
+                       public virtual void f2 () { }
+               }
+
+               class GenericMid<T, U> : GenericBase<T, Action<U>> {
+                       public virtual T f1 () { return default (T); }
+               }
+
+               class GenericChild<T> : GenericMid<T, int> {
+                       public override T f1 () { return default (T); }
+                       public override void f2 () { }
+               }
+
+               [Test]
+               public void GetBaseDefinition_OpenConstructedBaseType () // 36305
+               {
+                       var t = typeof (GenericChild<string>);
+
+                       var mi1 = t.GetMethod ("f1");
+                       var mi1_base = mi1.GetBaseDefinition ();
+
+                       Assert.AreEqual (typeof (GenericMid<string, int>), mi1_base.DeclaringType, "#1");
+
+                       var mi2 = t.GetMethod ("f2");
+                       var mi2_base = mi2.GetBaseDefinition ();
+
+                       Assert.AreEqual (typeof (GenericBase<string, Action<int>>), mi2_base.DeclaringType, "#2");
+               }
+
                class TestInheritedMethodA {
                        private void TestMethod ()
                        {