summaryrefslogtreecommitdiff
path: root/mcs/tests/gtest-078.cs
blob: 46ec88e450573f3780cf354d2341a1ab335452ea (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
using System;

struct S : IDisposable
{
	public static int hit;

	void IDisposable.Dispose ()
	{
		hit++;
	}

	public void Dispose ()
	{
		throw new ApplicationException ();
	}
}

class C : IDisposable
{

	void IDisposable.Dispose ()
	{
	}

	public void Dispose ()
	{
		throw new ApplicationException ();
	}
}

class Test
{
	public static int Main ()
	{
		S? nullable = null;
		using (var a = nullable) {
		}

		if (S.hit != 0)
			return 1;

		using (var s = new S ()) {
		}

		if (S.hit != 1)
			return 2;

		C c = null;
		GenMethod (c);
		
		using (S? a = nullable, b = nullable) {
		}
		
		if (S.hit != 1)
			return 3;

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

	static void GenMethod<T> (T t) where T : IDisposable
	{
		using (T t2 = t) {
		}
	}
}