Merge pull request #1322 from StephenMcConnel/bug23532
[mono.git] / mcs / tests / test-null-operator-05.cs
1 using System;
2
3 class CI
4 {
5         public string this [string i] { set { } get { return ""; } }
6         public int? this [int i] { set { } get { return 1; } }
7 }
8
9 class C
10 {
11         static int TestArrayAccess ()
12         {
13                 byte[] arr = null;
14                 var v = arr? [0];
15                 if (v != null)
16                         return 1;
17
18                 long?[] ar2 = null;
19                 var v2 = ar2? [-1];
20                 if (v2 != null)
21                         return 2;
22
23                 var v3 = arr? [0].GetHashCode () ?? 724;
24                 if (v3 != 724)
25                         return 3;
26
27                 string[] ar3 = null;
28                 var v4 = ar3?[0].Length;
29                 if (v4 != null)
30                         return 4;
31
32 // TODO: Disabled for now?
33 //        arr? [0] += 2;
34                 return 0;
35         }
36
37         static int TestIndexerAccess ()
38         {
39                 CI ci = null;
40                 var v = ci? ["x"];
41                 if (v != null)
42                         return 1;
43
44                 var v2 = ci? [0];
45                 if (v2 != null)
46                         return 2;
47
48                 var v3 = ci? [0].GetHashCode () ?? 724;
49                 if (v3 != 724)
50                         return 3;
51
52 // TODO: Disabled for now?
53 //       ci? [0] += 3;
54                 return 0;
55         }
56
57         static int Main ()
58         {
59                 int res;
60                 res = TestArrayAccess ();
61                 if (res != 0)
62                         return 10 + res;
63
64                 res = TestIndexerAccess ();
65                 if (res != 0)
66                         return 20 + res;
67
68                 Console.WriteLine ("ok");
69                 return 0;
70         }
71 }