Initial set of Ward sgen annotations (#5705)
[mono.git] / mcs / tests / test-780.cs
1 using System;
2
3 namespace MonoVirtuals
4 {
5         class X { }
6         class Y : X { }
7
8         class A
9         {
10                 public virtual int f (X o)
11                 {
12                         System.Console.WriteLine ("In A for X");
13                         return 5;
14                 }
15
16                 public virtual int f (Y o)
17                 {
18                         System.Console.WriteLine ("In A for Y");
19                         return 10;
20                 }
21
22                 public virtual int this[X o]
23                 {
24                         get
25                         {
26                                 System.Console.WriteLine ("In A for X");
27                                 return 5;
28                         }
29                 }
30
31                 public virtual int this[Y o]
32                 {
33                         get
34                         {
35                                 System.Console.WriteLine ("In A for Y");
36                                 return 10;
37                         }
38                 }
39         }
40
41         class B : A
42         {
43                 public override int f (X o)
44                 {
45                         base.f (o);
46                         throw new ApplicationException ("should not be called");
47                 }
48
49                 public override int this[X o]
50                 {
51                         get
52                         {
53                                 base.f (o);
54                                 throw new ApplicationException ("should not be called");
55                         }
56                 }
57         }
58
59         class C : B
60         {
61                 public override int f (X o)
62                 {
63                         System.Console.WriteLine ("In C for X");
64                         return base.f (o);
65                 }
66
67                 public override int f (Y o)
68                 {
69                         System.Console.WriteLine ("In C for Y");
70                         return base.f (o);
71                 }
72
73                 public override int this[X o]
74                 {
75                         get
76                         {
77                                 System.Console.WriteLine ("In C for X");
78                                 return base.f (o);
79                         }
80                 }
81
82                 public override int this[Y o]
83                 {
84                         get
85                         {
86                                 System.Console.WriteLine ("In C for Y");
87                                 return base.f (o);
88                         }
89                 }
90         }
91
92         class MainClass
93         {
94                 public static int Main ()
95                 {
96                         var o = new Y ();
97                         var c = new C ();
98                         if (c.f (o) != 10)
99                                 return 1;
100
101                         if (c[o] != 10)
102                                 return 2;
103
104                         return 0;
105                 }
106         }
107 }