blob: cd27013b5ff77c178883e9d169ef43a12a712864 (
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
72
73
74
75
76
77
78
79
|
using System;
struct Foo
{
public int Value;
public Foo (int value)
{
this.Value = value;
}
public static Foo operator - (Foo? f)
{
if (f.HasValue)
return new Foo (-f.Value.Value);
return new Foo (42);
}
}
struct Bar
{
public int Value;
public Bar (int value)
{
this.Value = value;
}
public static Bar? operator - (Bar? b)
{
if (b.HasValue)
return new Bar (-b.Value.Value);
return b;
}
}
class Test
{
static Foo NegateFoo (Foo f)
{
return -f;
}
static Foo NegateFooNullable (Foo? f)
{
return -f;
}
static Bar? NegateBarNullable (Bar? b)
{
return -b;
}
static Bar? NegateBar (Bar b)
{
return -b;
}
public static int Main ()
{
if (NegateFooNullable (null).Value != 42)
return 1;
if (NegateFoo (new Foo (2)).Value != -2)
return 2;
if (NegateBarNullable (null) != null)
return 3;
if (NegateBar (new Bar (2)).Value.Value != -2)
return 4;
Console.WriteLine ("OK");
return 0;
}
}
|