2002-10-19 Rachel Hestilow <hestilow@ximian.com>
[mono.git] / mcs / tests / test-148.cs
1 using System;
2 using System.Runtime.CompilerServices;
3
4 public interface X
5 {
6         [IndexerName ("Foo")]
7         int this [int a] {
8                 get;
9         }
10 }
11
12 public class Y : X
13 {
14         int X.this [int a] {
15                 get {
16                         return 1;
17                 }
18         }
19
20         [IndexerName ("Bar")]
21         public int this [int a] {
22                 get {
23                         return 2;
24                 }
25         }
26
27         [IndexerName ("Bar")]
28         public long this [double a] {
29                 get {
30                         return 3;
31                 }
32         }
33 }
34
35 public class Z : Y
36 {
37         [IndexerName ("Whatever")]
38         new public long this [double a] {
39                 get {
40                         return 4;
41                 }
42         }
43
44         public int InstanceTest ()
45         {
46                 double index = 5;
47
48                 Console.WriteLine ("INSTANCE TEST");
49
50                 if (this [index] != 4)
51                         return 6;
52                 if (base [index] != 3)
53                         return 7;
54
55                 return 0;
56         }
57
58         public static int Test ()
59         {
60                 Z z = new Z ();
61                 X x = (X) z;
62                 Y y = (Y) z;
63
64                 Console.WriteLine (z [1]);
65                 Console.WriteLine (y [2]);
66                 Console.WriteLine (x [3]);
67
68                 if (z [1] != 4)
69                         return 1;
70                 if (y [1] != 2)
71                         return 2;
72                 if (x [1] != 1)
73                         return 3;
74
75                 double index = 5;
76
77                 Console.WriteLine (z [index]);
78                 Console.WriteLine (y [index]);
79
80                 if (z [index] != 4)
81                         return 4;
82                 if (y [index] != 3)
83                         return 5;
84
85                 return z.InstanceTest ();
86         }
87
88         public static int Main ()
89         {
90                 int result = Test ();
91
92                 Console.WriteLine ("RESULT: " + result);
93
94                 return result;
95         }
96 }