Allow async block to capture this inside value types
authorMarek Safar <marek.safar@gmail.com>
Fri, 16 Sep 2011 12:11:37 +0000 (13:11 +0100)
committerMarek Safar <marek.safar@gmail.com>
Mon, 19 Sep 2011 10:56:41 +0000 (11:56 +0100)
mcs/mcs/expression.cs
mcs/tests/test-async-24.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_0.xml

index 2854e92cd9034a5c201c86baa03be2a756158a86..32241bf5c82a1b292a13e9afb1202779bf63b160 100644 (file)
@@ -6832,7 +6832,7 @@ namespace Mono.CSharp
                        if (ignoreAnonymous || ec.CurrentAnonymousMethod == null)
                                return true;
 
-                       if (ec.CurrentType.IsStruct && ec.CurrentIterator == null)
+                       if (ec.CurrentType.IsStruct && !(ec.CurrentAnonymousMethod is StateMachineInitializer))
                                return false;
 
                        return true;
diff --git a/mcs/tests/test-async-24.cs b/mcs/tests/test-async-24.cs
new file mode 100644 (file)
index 0000000..6593100
--- /dev/null
@@ -0,0 +1,37 @@
+// Compiler options: -langversion:future
+using System;
+using System.Threading.Tasks;
+using System.Threading;
+
+struct Struct
+{
+       object m_member;
+       public Struct (object member)
+       {
+               m_member = member;
+       }
+
+       public async Task<bool> AsyncMethod ()
+       {
+               bool b = (string)m_member == "1";
+               await Task.Factory.StartNew (() => -3);
+               b &= (string)m_member == "1";
+               return b;
+       }
+}
+
+class C
+{
+       static int Main ()
+       {
+               Struct s = new Struct ("1");
+               var t = s.AsyncMethod ();
+               if (!Task.WaitAll (new[] { t }, 2000))
+                       return 1;
+               
+               if (!t.Result)
+                       return 2;
+               
+               return 0;
+       }
+}
index 6c31b4e6bac3a0c5bca7d4f2e409a577cfd228d0..3ddc24d278aa913513a28531f8ccf299e340401f 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-async-24.cs">
+    <type name="Struct">
+      <method name="System.Threading.Tasks.Task`1[System.Boolean] AsyncMethod()">
+        <size>39</size>
+      </method>
+      <method name="Void .ctor(Object)">
+        <size>8</size>
+      </method>
+    </type>
+    <type name="C">
+      <method name="Int32 Main()">
+        <size>62</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="Struct+&lt;AsyncMethod&gt;c__async0">
+      <method name="Void MoveNext()">
+        <size>279</size>
+      </method>
+      <method name="Int32 &lt;&gt;m__0()">
+        <size>3</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>36</size>
+      </method>
+    </type>
+  </test>
   <test name="test-cls-00.cs">
     <type name="CLSCLass_6">
       <method name="Void .ctor()">