[mcs] Add codegen for null operator on result of awaited instance expression of prope...
[mono.git] / mcs / tests / test-anon-82.cs
1 //
2 // Tests different anonymous method caching scenarios
3 //
4
5 public delegate void StringSender (string str);
6 public delegate void VoidDelegate ();
7
8 public class MainClass
9 {
10         public static void Main()
11         {
12                 MainClass mc = new MainClass ();
13                 VoidDelegate del = new VoidDelegate (
14                         delegate {
15                                 StringSender ss = delegate (string s) {
16                                         SimpleCallback(mc, s);
17                                 };
18                                 ss("Yo!");
19                         }
20                 );
21                 del();
22                 
23                 mc.Test2 (10);
24                 mc.Test3 (20);
25                 mc.Test4 ();
26                 mc.Test5 (50);
27         }
28         
29         void Test2 (int a)
30         {
31                 StringSender d = delegate (string s) {
32                         VoidDelegate d2 = delegate {
33                                 s = "10";
34                         };
35                 };
36         }
37         
38         void Test3 (int a)
39         {
40                 int u = 8;
41                 VoidDelegate d = delegate () { u = 9; };
42                 VoidDelegate d2 = delegate () { };
43         }
44
45         void Test4 ()
46         {
47                 VoidDelegate d = delegate () {
48                         VoidDelegate d2 = delegate () {
49                                 int a = 9;
50                                 VoidDelegate d3 = delegate () {
51                                         VoidDelegate d4 = delegate () {
52                                                 a = 3;
53                                         };
54                                 };
55                         };
56                 };
57         }
58         
59         int a;
60         int b;
61         
62         delegate int D (int a);
63         
64         void Test5 (int arg)
65         {
66                 D d2 = delegate (int i) {
67                         D d1 = delegate (int a) {
68                                 return a;
69                         };
70
71                         return d1 (9) + arg;
72                 };
73         }
74         
75         static void SimpleCallback (MainClass mc, string str)
76         {
77                 System.Console.WriteLine(str);
78         }
79 }