summaryrefslogtreecommitdiff
path: root/mcs/tests/test-null-operator-05.cs
blob: ecbc6019059105b87a997e1ee08f830545102d92 (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
using System;

class CI
{
	public string this [string i] { set { } get { return ""; } }
	public int? this [int i] { set { } get { return 1; } }
}

class C
{
	static int TestArrayAccess ()
	{
		byte[] arr = null;
		var v = arr? [0];
		if (v != null)
			return 1;

		long?[] ar2 = null;
		var v2 = ar2? [-1];
		if (v2 != null)
			return 2;

		var v3 = arr? [0].GetHashCode () ?? 724;
		if (v3 != 724)
			return 3;

		string[] ar3 = null;
		var v4 = ar3?[0].Length;
		if (v4 != null)
			return 4;

// TODO: Disabled for now?
//        arr? [0] += 2;
		return 0;
	}

	static int TestIndexerAccess ()
	{
		CI ci = null;
		var v = ci? ["x"];
		if (v != null)
			return 1;

		var v2 = ci? [0];
		if (v2 != null)
			return 2;

		var v3 = ci? [0].GetHashCode () ?? 724;
		if (v3 != 724)
			return 3;

// TODO: Disabled for now?
//       ci? [0] += 3;
		return 0;
	}

	static int Main ()
	{
		int res;
		res = TestArrayAccess ();
		if (res != 0)
			return 10 + res;

		res = TestIndexerAccess ();
		if (res != 0)
			return 20 + res;

		Console.WriteLine ("ok");
		return 0;
	}
}