[mcs] Mutate nested storey initialization only when needed. Fixes #28211
authorMarek Safar <marek.safar@gmail.com>
Fri, 3 Apr 2015 13:45:06 +0000 (15:45 +0200)
committerMarek Safar <marek.safar@gmail.com>
Fri, 3 Apr 2015 13:46:13 +0000 (15:46 +0200)
mcs/mcs/anonymous.cs
mcs/tests/test-anon-177.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_5.xml

index 1063fb1b07774bbf529adea254919c0cd18f71f1..12bf992bbcca22df81e61c6adde66b10d3216f3a 100644 (file)
@@ -1920,17 +1920,16 @@ namespace Mono.CSharp {
 
                        var delegate_method = method.Spec;
                        if (storey != null && storey.MemberName.IsGeneric) {
-                               TypeSpec t = storey.Instance.Type;
-
                                //
                                // Mutate anonymous method instance type if we are in nested
                                // hoisted generic anonymous method storey
                                //
                                if (ec.IsAnonymousStoreyMutateRequired) {
-                                       t = storey.Mutator.Mutate (t);
+                                       ec.Emit (OpCodes.Ldftn, delegate_method);
+                               } else {
+                                       TypeSpec t = storey.Instance.Type;
+                                       ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
                                }
-
-                               ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
                        } else {
                                if (delegate_method.IsGeneric) {
                                        TypeParameterSpec[] tparams;
diff --git a/mcs/tests/test-anon-177.cs b/mcs/tests/test-anon-177.cs
new file mode 100644 (file)
index 0000000..cb31425
--- /dev/null
@@ -0,0 +1,25 @@
+using System;
+using System.Linq;
+using System.Collections.Generic;
+
+class X
+{
+       public static void Execute<TArg>(TArg args)
+       {
+               Action a = () => {
+                       List<string> s = new List<string> () {
+                               "test"
+                       };
+
+                       object res = null;
+                       var res2 = s.Select(acrl => acrl.Select(acr => res)).ToArray ();
+               };
+
+               a ();
+       }
+
+       public static void Main ()
+       {
+               Execute<string> (null);
+       }
+}
\ No newline at end of file
index 0cfc63322524434b66c660b5fa0f1f261106e5d6..5afcd1aa90606f5dfd6a3f71a50fcfbb01ab2a0b 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-anon-177.cs">
+    <type name="X">
+      <method name="Void Execute[TArg](TArg)" attrs="150">
+        <size>21</size>
+      </method>
+      <method name="Void Main()" attrs="150">
+        <size>8</size>
+      </method>
+      <method name="Void &lt;Execute`1&gt;m__0[TArg]()" attrs="145">
+        <size>58</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="X+&lt;Execute&gt;c__AnonStorey0`1[TArg]">
+      <method name="System.Collections.Generic.IEnumerable`1[System.Object] &lt;&gt;m__0(System.String)" attrs="131">
+        <size>26</size>
+      </method>
+      <method name="System.Object &lt;&gt;m__1(Char)" attrs="131">
+        <size>14</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-anon-18.cs">
     <type name="A">
       <method name="Void Invoke()" attrs="454">