[verifier] Add test for structs.
[mono.git] / mono / tests / verifier / valid_ref_return.cs
1 using System;
2
3 struct Point {
4     public int x;
5     public int y;
6 }
7
8 class Foo {
9         static int X = 10;
10         static int[] Arr = new int[1];
11         int y;
12
13         static void Main () {
14         }
15
16         static ref int ReturnStatic () {
17                 return ref X;
18         }
19
20         ref int ReturnField () {
21                 return ref this.y;
22         }
23
24         ref int ReturnArrayElement () {
25                 return ref Arr [0];
26         }
27
28         ref int ReturnArg (ref int arg) {
29                 return ref arg;
30         }
31
32         ref int TwoReturns (bool b) {
33                 if (b) 
34                         return ref X;
35                 else
36                         return ref Arr [0];
37         }
38
39         ref int LocalVarRet (bool b) {
40                 ref int x = ref X;
41                 ReturnArg (ref x);
42                 return ref x;
43         }
44
45         ref int ReturnRet (ref int arg) {
46                 return ref ReturnArg (ref arg);
47         }
48
49         ref int ReturnFromCatch () {
50                 try {
51                         return ref X;
52                 } catch (Exception) {
53                         return ref X;
54                 } 
55         }
56
57         ref int ReturnFunc () {
58                 return ref ReturnStatic ();
59         }
60
61     Point mp;
62
63     ref int Pick (bool b, ref Point p) {
64         if (b)
65             return ref p.x;
66         else
67             return ref p.y;
68     }
69
70     void F (bool b) {
71         Point lp = new Point {x = 3, y = 3};
72         ref int z = ref Pick (b, ref lp);
73         z = 4;
74         ref int z2 = ref Pick (b, ref mp);
75         z2 = 5;
76     }
77 }