[mcs] Allow properties and indexers of by-ref values to be set without setter
[mono.git] / mcs / tests / gtest-397.cs
1 using System;
2
3 struct Foo
4 {
5         public int Value;
6
7         public Foo (int value)
8         {
9                 this.Value = value;
10         }
11
12         public static Foo operator - (Foo? f)
13         {
14                 if (f.HasValue)
15                         return new Foo (-f.Value.Value);
16
17                 return new Foo (42);
18         }
19 }
20
21 struct Bar
22 {
23         public int Value;
24
25         public Bar (int value)
26         {
27                 this.Value = value;
28         }
29
30         public static Bar? operator - (Bar? b)
31         {
32                 if (b.HasValue)
33                         return new Bar (-b.Value.Value);
34
35                 return b;
36         }
37 }
38
39 class Test
40 {
41
42         static Foo NegateFoo (Foo f)
43         {
44                 return -f;
45         }
46
47         static Foo NegateFooNullable (Foo? f)
48         {
49                 return -f;
50         }
51
52         static Bar? NegateBarNullable (Bar? b)
53         {
54                 return -b;
55         }
56
57         static Bar? NegateBar (Bar b)
58         {
59                 return -b;
60         }
61
62         public static int Main ()
63         {
64                 if (NegateFooNullable (null).Value != 42)
65                         return 1;
66
67                 if (NegateFoo (new Foo (2)).Value != -2)
68                         return 2;
69
70                 if (NegateBarNullable (null) != null)
71                         return 3;
72
73                 if (NegateBar (new Bar (2)).Value.Value != -2)
74                         return 4;
75
76                 Console.WriteLine ("OK");
77                 return 0;
78         }
79 }