blob: 63cae1282ee984b2337b3fbdccfebbdc131795a6 (
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
using System;
struct S
{
public int Prop { get; set; }
}
interface I
{
int Method ();
}
class CI : I
{
public int Method ()
{
return 33;
}
public int Prop { get; set; }
}
class C
{
static int prop_calls;
static string Prop {
get {
++prop_calls;
return null;
}
}
static int TestArray ()
{
int[] k = null;
var t1 = k?.ToString ();
if (t1 != null)
return 1;
var t2 = k?.GetLength (0);
if (t2 != null)
return 2;
var t3 = k?.Length;
if (t3 != null)
return 3;
var t4 = k?.GetLength (0).ToString () ?? "N";
if (t4 != "N")
return 4;
var t5 = k?.Length.ToString () ?? "N";
if (t5 != "N")
return 5;
k = new int[] { 3 };
var t11 = k?.ToString ();
if (t11.GetType () != typeof (string))
return 10;
var t12 = k?.GetLength (0);
if (t12.GetType () != typeof (int))
return 11;
var t13 = k?.Length;
if (t13.GetType () != typeof (int))
return 12;
return 0;
}
static int TestReferenceType ()
{
string s = null;
var t1 = s?.Split ();
if (t1 != null)
return 1;
var t2 = s?.Length;
if (t2 != null)
return 2;
var t3 = Prop?.Length;
if (t3 != null)
return 3;
if (prop_calls != 1)
return 4;
var t4 = Prop?.Split ();
if (t4 != null)
return 5;
if (prop_calls != 2)
return 6;
return 0;
}
static int TestGeneric<T> (T t) where T : class, I
{
var t1 = t?.Method ();
if (t1 != null)
return 1;
T[] at = null;
var t2 = at?.Length;
if (t2 != null)
return 2;
return 0;
}
static int TestNullable ()
{
int? i = 4;
var m = i?.CompareTo (3);
if (m.GetType () != typeof (int))
return 1;
if (m != 1)
return 2;
DateTime? dt = null;
dt?.ToString ();
if (dt?.ToString () != null)
return 3;
byte? b = 0;
if (b?.ToString () != "0")
return 4;
S? s = null;
var p1 = s?.Prop;
if (p1 != null)
return 5;
return 0;
}
static int Main ()
{
int res;
res = TestNullable ();
if (res != 0)
return 100 + res;
res = TestArray ();
if (res != 0)
return 200 + res;
res = TestReferenceType ();
if (res != 0)
return 300 + res;
CI ci = null;
res = TestGeneric<CI> (ci);
if (res != 0)
return 400 + res;
Console.WriteLine ("ok");
return 0;
}
}
|