Merge pull request #5675 from mono/glib-debug-symbols
[mono.git] / mcs / tests / test-null-operator-08.cs
1 using System;
2
3 interface I
4 {
5         void Foo (bool expected);
6 }
7
8 struct S : I
9 {
10         bool flag;
11
12         public void Foo (bool expected)
13         {
14                 Console.WriteLine (flag);
15                 if (expected != flag)
16                         throw new ApplicationException ();
17
18                 flag = true;
19         }
20 }
21
22 class Program
23 {
24         static void M<T> (T x)
25         {
26                 object s = x?.ToString ();
27                 System.Console.WriteLine (s);
28
29                 var h = x?.GetHashCode ();
30                 System.Console.WriteLine (h);
31         }
32
33         static void M2<T> (T[] x)
34         {
35                 object s = x?.ToString ();
36                 System.Console.WriteLine (s);
37
38                 var h = x?.GetHashCode ();
39                 System.Console.WriteLine (h);
40         }
41
42         static void M2_2<T> (T[] x)
43         {
44                 object s = x[0]?.ToString ();
45                 System.Console.WriteLine (s);
46
47                 var h = x[0]?.GetHashCode ();
48                 System.Console.WriteLine (h);
49         }
50
51         static void M3<T> (T? x) where T : struct
52         {
53                 object s = x?.ToString ();
54                 System.Console.WriteLine (s);
55
56                 var h = x?.GetHashCode ();
57                 System.Console.WriteLine (h);
58         }
59
60         static void TestAddress_1<T> (T t) where T : I
61         {
62                 t?.Foo (false);
63                 t?.Foo (true);
64         }
65
66         static void TestAddress_2<T> (T[] t) where T : I
67         {
68                 t[0]?.Foo (false);
69                 t[0]?.Foo (true);
70         }
71
72         static void Main()
73         {
74                 M<string> (null);
75                 M (1);
76                 M("X");
77
78                 M2<int> (null);
79                 M2<string> (null);
80                 M2 (new [] { 1 });
81                 M2 (new [] { "x" });
82
83                 M2_2 (new string [1]);
84                 M2_2 (new int [1]);
85
86                 M3<int> (1);
87                 M3<byte> (null);
88
89                 TestAddress_1 (new S ());
90                 var ar = new [] { new S () };
91                 TestAddress_2 (ar);
92         }
93 }