Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2011-08-13 21:10:13 +0400
committerMarek Safar <marek.safar@gmail.com>2011-08-13 21:15:00 +0400
commit6d8fab26466c7557d2e5e30fa08bdeede5bfbfb7 (patch)
tree316ab83ff24b5a2c2d332e7cec9482396b9d7268 /mcs/tests/test-async-18.cs
parentb2a0c0809d5f2d5b8c3319884be7ae0b602d0b52 (diff)
Implement hoisting of anonymous methods with variables inside async body
Diffstat (limited to 'mcs/tests/test-async-18.cs')
-rw-r--r--mcs/tests/test-async-18.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/mcs/tests/test-async-18.cs b/mcs/tests/test-async-18.cs
new file mode 100644
index 00000000000..898d9ed4ded
--- /dev/null
+++ b/mcs/tests/test-async-18.cs
@@ -0,0 +1,73 @@
+// Compiler options: -langversion:future
+using System;
+using System.Threading.Tasks;
+using System.Threading;
+
+class Tester
+{
+ async Task<int> Lambda_1 ()
+ {
+ int res = 1;
+ {
+ int a = 8;
+ Func<int> f = () => a;
+ res = await Task.Factory.StartNew (f);
+ res += f ();
+ }
+
+ return res - 16;
+ }
+
+ async Task<int> Lambda_2 ()
+ {
+ int res = 1;
+ {
+ int a = 8;
+ Func<int> f = () => a + res;
+ res = await Task.Factory.StartNew (f);
+ res += f ();
+ }
+
+ return res - 26;
+ }
+
+ async Task<int> Lambda_3<T> ()
+ {
+ int res = 1;
+ {
+ int a = 8;
+ Func<int> f = () => a;
+ res = await Task.Factory.StartNew (f);
+ res += f ();
+ }
+
+ return res - 16;
+ }
+
+ public static int Main ()
+ {
+ var t = new Tester ().Lambda_1 ();
+ if (!Task.WaitAll (new [] { t }, 1000))
+ return 1;
+
+ if (t.Result != 0)
+ return 2;
+
+ t = new Tester ().Lambda_2 ();
+ if (!Task.WaitAll (new [] { t }, 1000))
+ return 3;
+
+ if (t.Result != 0)
+ return 4;
+
+ t = new Tester ().Lambda_3<ulong>();
+ if (!Task.WaitAll (new [] { t }, 1000))
+ return 5;
+
+ if (t.Result != 0)
+ return 6;
+
+ Console.WriteLine ("ok");
+ return 0;
+ }
+}