diff options
author | Aleksey Kliger (λgeek) <akliger@gmail.com> | 2017-10-18 15:11:51 +0300 |
---|---|---|
committer | Ludovic Henry <luhenry@microsoft.com> | 2017-10-18 15:11:51 +0300 |
commit | 3d00ea31a73950cc42ead906b2a18b6dec2ff7da (patch) | |
tree | 2090fcc87729e8eb4db6f17f108a60998db33992 /mcs | |
parent | 4bd3aa215838ca21be8bcc4bac059312f4d1b069 (diff) |
[sre] Register a canonical reflected method for a methodspec token. (Fixes #60233) (#5813)
* [test] ILGenerator test for duplicate methodspec tokens
Regression test for [Bugzilla #60233](https://bugzilla.xamarin.com/show_bug.cgi?id=60233)
* [sre] mono_dynamic_image_register_token: Change asserts to warnings
This partly relaxes the changes in 792b5367cd3a6ffa1a192c4d2d7ace3509cbb646
which added the assertions.
In practice the assertions introduced a crash in heavy uses of
System.Reflection.Emit such as unit testing frameworks and dynamic languages.
We still want to know if there are surprising uses of
mono_dynamic_image_register_token, but we don't need a crash. SRE used to work
before 792b5367cd3a6ffa1a192c4d2d7ace3509cbb646, so no need to break it.
* [sre] Register a canonical reflected method for a methodspec token (Fixes #60233)
This is like the fix for [bugzilla
59364](https://bugzilla.xamarin.com/show_bug.cgi?id=59364) but this time it's a
methodspec token, not a memberref token.
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/Test/System.Reflection.Emit/ILGeneratorTest.cs | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/mcs/class/corlib/Test/System.Reflection.Emit/ILGeneratorTest.cs b/mcs/class/corlib/Test/System.Reflection.Emit/ILGeneratorTest.cs index c943d6859ca..b31ed2e117e 100644 --- a/mcs/class/corlib/Test/System.Reflection.Emit/ILGeneratorTest.cs +++ b/mcs/class/corlib/Test/System.Reflection.Emit/ILGeneratorTest.cs @@ -524,11 +524,13 @@ namespace MonoTests.System.Reflection.Emit } - public class Base { + public class Base<T> { public int x; + + public void M () { } } - public class Derived : Base { + public class Derived : Base<string> { } [Test] @@ -540,7 +542,7 @@ namespace MonoTests.System.Reflection.Emit // // Regression test for bugzilla #59364 - var f1 = typeof (Base).GetField ("x"); + var f1 = typeof (Base<string>).GetField ("x"); var f2 = typeof (Derived).GetField ("x"); var value_getter = typeof (RuntimeFieldHandle).GetProperty("Value").GetMethod; @@ -572,5 +574,42 @@ namespace MonoTests.System.Reflection.Emit Assert.AreEqual ("1", s); } + [Test] + public void MethodSpecTokenSame () { + DefineBasicMethod (); + // Get the same method from a base generic instance and + // a type derived from it so that the + // MemberInfo:DeclaredType differs but the tokens are + // the same. + // + // Regression test for bugzilla #60233 + + var m1 = typeof (Base<string>).GetMethod ("M"); + var m2 = typeof (Derived).GetMethod ("M"); + + var il = il_gen; + + var loc = il.DeclareLocal (typeof (Derived)); + + il.Emit (OpCodes.Newobj, typeof (Derived).GetConstructor(new Type[]{})); + il.Emit (OpCodes.Stloc, loc); + il.Emit (OpCodes.Ldloc, loc); + il.Emit (OpCodes.Call, m1); + il.Emit (OpCodes.Ldloc, loc); + il.Emit (OpCodes.Call, m2); + il.Emit (OpCodes.Ldstr, "1"); + il.Emit (OpCodes.Ret); + + var baked = tb.CreateType (); + + var x = Activator.CreateInstance (baked); + var m = baked.GetMethod ("F"); + + var s = m.Invoke (x, null); + + Assert.AreEqual ("1", s); + + } + } } |