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