Skip to content

Commit 722b18c

Browse files
committed
Add test for virtual method dispatch
1 parent 2c9263a commit 722b18c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/tests/JIT/interpreter/Interpreter.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44
using System;
55
using System.Runtime.CompilerServices;
66

7+
public interface ITest
8+
{
9+
public int VirtualMethod();
10+
}
11+
12+
public class BaseClass : ITest
13+
{
14+
public int NonVirtualMethod()
15+
{
16+
return 0xbaba;
17+
}
18+
19+
public virtual int VirtualMethod()
20+
{
21+
return 0xbebe;
22+
}
23+
}
24+
25+
public class DerivedClass : BaseClass
26+
{
27+
public override int VirtualMethod()
28+
{
29+
return 0xdede;
30+
}
31+
32+
}
33+
734
public struct MyStruct
835
{
936
public int a;
@@ -71,6 +98,8 @@ public static void RunInterpreterTests()
7198
// Environment.FailFast(null);
7299
if (!TestFloat())
73100
Environment.FailFast(null);
101+
if (!TestVirtual())
102+
Environment.FailFast(null);
74103
}
75104

76105
public static int Mul4(int a, int b, int c, int d)
@@ -209,4 +238,26 @@ public static bool TestFloat()
209238

210239
return true;
211240
}
241+
242+
public static bool TestVirtual()
243+
{
244+
BaseClass bc = new DerivedClass();
245+
ITest itest = bc;
246+
247+
if (bc.NonVirtualMethod() != 0xbaba)
248+
return false;
249+
if (bc.VirtualMethod() != 0xdede)
250+
return false;
251+
if (itest.VirtualMethod() != 0xdede)
252+
return false;
253+
bc = new BaseClass();
254+
itest = bc;
255+
if (bc.NonVirtualMethod() != 0xbaba)
256+
return false;
257+
if (bc.VirtualMethod() != 0xbebe)
258+
return false;
259+
if (itest.VirtualMethod() != 0xbebe)
260+
return false;
261+
return true;
262+
}
212263
}

0 commit comments

Comments
 (0)