forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHub_51918.cs
More file actions
61 lines (49 loc) · 1.31 KB
/
GitHub_51918.cs
File metadata and controls
61 lines (49 loc) · 1.31 KB
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
using System;
public interface IGeneric<T>
{
int InterfaceMethod();
}
public interface IMakeClassMethodSealedVirtual
{
int ClassMethod();
}
public class GenericClass<A,B> : IMakeClassMethodSealedVirtual
{
public static int _sv1;
public static int _sv2;
public int _v1;
public int _v2;
public GenericClass()
{
_v1 = _sv1++;
_v2 = _sv2++;
}
public int ClassMethod()
{
return _v1 - _v2;
}
public InnerClass GetInnerClass() => new InnerClass(this);
public sealed class InnerClass : IGeneric<A>
{
GenericClass<A,B> _localPointer;
public InnerClass(GenericClass<A,B> pointer)
{
_localPointer = pointer;
}
public int InterfaceMethod() => _localPointer.ClassMethod();
}
}
public class GitHub_51918
{
public static int Main()
{
IGeneric<int> genInterface = new GenericClass<int, string>().GetInnerClass();
// Validate that two levels of inlining we don't behave incorrectly due to generic
// canonicalization. (Devirtualize the interface call, and then devirtualize/inline
// the call to ClassMethod)
Console.WriteLine(genInterface.InterfaceMethod());
if (genInterface.InterfaceMethod() == 0)
return 100;
return 1;
}
}