Merge pull request #5439 from alexrp/master
[mono.git] / mcs / tests / test-async-03.cs
1 using System.Runtime.CompilerServices;
2 using System.Threading.Tasks;
3
4 static class S
5 {
6         public static A GetAwaiter (this int i)
7         {
8                 return new A ();
9         }
10 }
11
12 class A : INotifyCompletion
13 {
14         bool IsCompleted {
15                 get {
16                         return true;
17                 }
18         }
19         
20         void INotifyCompletion.OnCompleted (System.Action a)
21         {
22         }
23         
24         int GetResult ()
25         {
26                 return 3;
27         }
28         
29         static async Task<int> Test1 ()
30         {
31                 await checked (1);
32                 return await checked (2);
33         }
34
35         static async Task<int> Test2 ()
36         {
37                 await checked (1);
38                 return 4;
39         }
40         
41         static async Task Test3 ()
42         {
43                 await checked (1);
44         }
45
46         public static int Main ()
47         {
48                 var r = Test1 ();
49                 System.Console.WriteLine (r.Result);
50                 if (r.Result != 3)
51                         return 1;
52
53                 r = Test2 ();
54                 System.Console.WriteLine (r.Result);
55                 if (r.Result != 4)
56                         return 2;
57                 
58                 Test3();
59                 return 0;
60         }
61 }