blob: 4d3c9180be2e8f7a0bad60702e6bbe544a35098f (
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
|
// Static fields in generic types: this is a runtime/JIT-only test
//
// We need to make sure that we're instantiating each closed generic
// type (ie. "Test<int>") only once.
using System;
public class Test<T>
{
public static int Count;
public void Foo ()
{
Count++;
}
public int GetCount ()
{
return Count;
}
}
class X
{
static int DoTheTest<T> ()
{
Test<T> test = new Test<T> ();
test.Foo ();
if (test.GetCount () != 1)
return 1;
if (Test<T>.Count != 1)
return 2;
test.Foo ();
if (test.GetCount () != 2)
return 3;
if (Test<T>.Count != 2)
return 4;
test.Foo ();
if (test.GetCount () != 3)
return 5;
if (Test<T>.Count != 3)
return 6;
return 0;
}
static int Main ()
{
int result = DoTheTest<int> ();
if (result != 0)
return result;
result = DoTheTest<long> () + 10;
if (result != 10)
return result;
Test<int>.Count = 0;
++Test<long>.Count;
result = DoTheTest<int> () + 20;
if (result != 20)
return result;
if (Test<int>.Count != 3)
return 31;
if (Test<long>.Count != 4)
return 32;
Test<float>.Count = 5;
if (Test<int>.Count != 3)
return 33;
if (Test<long>.Count != 4)
return 34;
return 0;
}
}
|