[metadata] Fix leaks when handling a few attributes (#16675)
[mono-project.git] / mcs / tests / test-null-operator-08.cs
blobb988e49078d747700f195de09971d0183a2c3839
1 using System;
3 interface I
5 void Foo (bool expected);
8 struct S : I
10 bool flag;
12 public void Foo (bool expected)
14 Console.WriteLine (flag);
15 if (expected != flag)
16 throw new ApplicationException ();
18 flag = true;
22 class Program
24 static void M<T> (T x)
26 object s = x?.ToString ();
27 System.Console.WriteLine (s);
29 var h = x?.GetHashCode ();
30 System.Console.WriteLine (h);
33 static void M2<T> (T[] x)
35 object s = x?.ToString ();
36 System.Console.WriteLine (s);
38 var h = x?.GetHashCode ();
39 System.Console.WriteLine (h);
42 static void M2_2<T> (T[] x)
44 object s = x[0]?.ToString ();
45 System.Console.WriteLine (s);
47 var h = x[0]?.GetHashCode ();
48 System.Console.WriteLine (h);
51 static void M3<T> (T? x) where T : struct
53 object s = x?.ToString ();
54 System.Console.WriteLine (s);
56 var h = x?.GetHashCode ();
57 System.Console.WriteLine (h);
60 static void TestAddress_1<T> (T t) where T : I
62 t?.Foo (false);
63 t?.Foo (true);
66 static void TestAddress_2<T> (T[] t) where T : I
68 t[0]?.Foo (false);
69 t[0]?.Foo (true);
72 static void Main()
74 M<string> (null);
75 M (1);
76 M("X");
78 M2<int> (null);
79 M2<string> (null);
80 M2 (new [] { 1 });
81 M2 (new [] { "x" });
83 M2_2 (new string [1]);
84 M2_2 (new int [1]);
86 M3<int> (1);
87 M3<byte> (null);
89 TestAddress_1 (new S ());
90 var ar = new [] { new S () };
91 TestAddress_2 (ar);