6350f1ec2514f24ad73f465525774ad7603f1b69
[mono.git] / mono / tests / verifier / valid_ref_return.cs
1 using System;
2
3 class Foo {
4         static int X = 10;
5         static int[] Arr = new int[1];
6         int y;
7
8         static void Main () {
9         }
10
11         static ref int ReturnStatic () {
12                 return ref X;
13         }
14
15         ref int ReturnField () {
16                 return ref this.y;
17         }
18
19         ref int ReturnArrayElement () {
20                 return ref Arr [0];
21         }
22
23         ref int ReturnArg (ref int arg) {
24                 return ref arg;
25         }
26
27         ref int TwoReturns (bool b) {
28                 if (b) 
29                         return ref X;
30                 else
31                         return ref Arr [0];
32         }
33
34         ref int LocalVarRet (bool b) {
35                 ref int x = ref X;
36                 ReturnArg (ref x);
37                 return ref x;
38         }
39
40         ref int ReturnRet (ref int arg) {
41                 return ref ReturnArg (ref arg);
42         }
43
44         ref int ReturnFromCatch () {
45                 try {
46                         return ref X;
47                 } catch (Exception) {
48                         return ref X;
49                 } 
50         }
51
52         ref int ReturnFunc () {
53                 return ref ReturnStatic ();
54         }
55 }