Merge pull request #5439 from alexrp/master
[mono.git] / mcs / tests / gtest-274.cs
1 using System;
2
3 public struct Foo
4 {
5         public readonly long Value;
6
7         public Foo (long value)
8         {
9                 this.Value = value;
10         }
11
12         public static implicit operator Foo (long value)
13         {
14                 return new Foo (value);
15         }
16 }
17
18 public struct Bar
19 {
20         public readonly Foo Foo;
21
22         public Bar (Foo foo)
23         {
24                 this.Foo = foo;
25         }
26
27         public static implicit operator Bar (Foo foo)
28         {
29                 return new Bar (foo);
30         }
31 }
32
33 public struct Baz
34 {
35         public readonly Foo Foo;
36
37         public Baz (Foo foo)
38         {
39                 this.Foo = foo;
40         }
41
42         public static explicit operator Baz (Foo foo)
43         {
44                 return new Baz (foo);
45         }
46 }
47
48 struct S
49 {
50         public static implicit operator bool?(S arg)
51         {
52                 throw new ApplicationException ("should not be called");
53         }
54 }
55
56 class X
57 {
58         public static int Main ()
59         {
60                 int a = 3;
61                 int? b = a;
62                 int? b0 = null;
63
64                 Foo? f1 = a;
65                 Foo? f2 = b;
66                 Foo? f3 = b0;
67                 Foo f4 = (Foo) b;
68
69                 Bar? b1 = f1;
70                 Bar? b2 = f2;
71                 Bar? b3 = f3;
72                 Bar b4 = (Bar) f2;
73
74                 Baz? z1 = (Baz?) f1;
75                 Baz? z2 = (Baz?) f2;
76                 Baz? z3 = (Baz?) f3;
77                 Baz z4 = (Baz) f2;
78
79                 S? s = null;
80                 bool? g = s;
81                 if (g != null)
82                         return 1;
83
84                 return 0;
85         }
86 }