[interp] Fall back to old implementation when calling on proxy
[mono-project.git] / mcs / tests / test-async-69.cs
blobaf133f953c50ee1cc4e0fcdb6bf122c3484d2d17
1 using System;
2 using System.Threading.Tasks;
4 class Test
6 static bool fin;
8 static async Task<int> YieldValue (int a)
10 await Task.Yield ();
11 return a;
14 static async Task<int> TestFinallyWithReturn (int value)
16 fin = false;
17 try {
18 if (value > 4)
19 return 5;
21 value += 10;
22 Console.WriteLine ("try");
23 } finally {
24 fin = true;
25 Console.WriteLine ("finally");
26 value += await YieldValue (100);
29 value += 1000;
30 Console.WriteLine ("over");
32 return value;
35 static async Task TestFinallyWithReturnNoValue (int value)
37 fin = false;
38 try {
39 if (value > 4)
40 return;
42 value += 10;
43 Console.WriteLine ("try");
44 } finally {
45 fin = true;
46 Console.WriteLine ("finally");
47 value += await YieldValue (100);
50 value += 1000;
51 Console.WriteLine ("over");
54 static async Task<int> TestFinallyWithGoto (int value)
56 fin = false;
57 try {
58 if (value > 4)
59 goto L;
61 value += 10;
62 Console.WriteLine ("try");
63 } finally {
64 fin = true;
65 Console.WriteLine ("finally");
66 value += await YieldValue (100);
68 value += 1000;
70 Console.WriteLine ("over");
71 return value;
74 static async Task<int> TestFinallyWithGotoAndReturn (int value)
76 fin = false;
77 try {
78 if (value > 4)
79 goto L;
81 value += 10;
82 Console.WriteLine ("try");
83 if (value > 12)
84 return 9;
85 } finally {
86 fin = true;
87 Console.WriteLine ("finally");
88 value += await YieldValue (100);
90 value += 1000;
92 Console.WriteLine ("over");
93 return value;
96 public static int Main ()
98 if (TestFinallyWithReturn (9).Result != 5)
99 return 1;
101 if (!fin)
102 return 2;
104 if (TestFinallyWithReturn (1).Result != 1111)
105 return 3;
107 if (!fin)
108 return 4;
110 TestFinallyWithReturnNoValue (9).Wait ();
111 if (!fin)
112 return 5;
114 TestFinallyWithReturnNoValue (1).Wait ();
115 if (!fin)
116 return 6;
118 if (TestFinallyWithGoto (9).Result != 109)
119 return 7;
121 if (!fin)
122 return 8;
124 if (TestFinallyWithGoto (1).Result != 1111)
125 return 9;
127 if (!fin)
128 return 10;
130 if (TestFinallyWithGotoAndReturn (9).Result != 109)
131 return 11;
133 if (!fin)
134 return 12;
136 if (TestFinallyWithGotoAndReturn (1).Result != 1111)
137 return 13;
139 if (!fin)
140 return 14;
142 if (TestFinallyWithGotoAndReturn (3).Result != 9)
143 return 15;
145 if (!fin)
146 return 16;
148 Console.WriteLine ("ok");
149 return 0;