Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / gtest-117.cs
1 // Compiler options: -warnaserror
2
3 using System;
4
5 enum E { Item };
6
7 public interface IFoo<T>
8 { }
9
10 public class Foo<T>
11 {
12         public static bool Test (T x)
13         {
14                 return x is IFoo<T>;
15         }
16         
17         public static bool Test ()
18         {
19                 T t = default (T);
20                 return t is int;
21         }
22         
23         public static bool TestB ()
24         {
25                 T t = default (T);
26                 return t is int?;
27         }
28 }
29
30 class Y<T> where T : struct
31 {
32         public bool Foo ()
33         {
34                 object o = null;
35                 return o is System.Nullable <T>;
36         }
37 }
38
39 class X
40 {
41         public static bool TestA (object o)
42         {
43                 return o is int?;
44         }
45         
46         public static bool TestB<T> (T o)
47         {
48                 return o is int[];
49         }
50         
51         public static int TestC ()
52         {
53                 int? i = null;
54                 if (i is int) {
55                         return (int) i;
56                 }
57                 
58                 return 3;
59         }
60         
61         static bool Check1 (E? e)
62         {
63                 return e is Enum;
64         }
65
66         static bool Check2<T> (E e) where T : struct
67         {
68                 return e is T;
69         }
70         
71         public static int Main ()
72         {
73                 if (Foo<int>.Test (3))
74                         return 1;
75                 
76                 if (!Foo<int>.Test())
77                         return 2;
78                 
79                 // False expected int? != null
80                 if (Foo<int?>.TestB())
81                         return 3;
82
83                 int? i = 0;
84                 if (!TestA(i))
85                         return 4;
86                 
87                 int[] a = new int[0];
88                 if (!TestB(a))
89                         return 5;
90                 
91                 if (TestC () != 3)
92                         return 6;
93                 
94                 if (Check1 (null))
95                         return 7;
96
97                 if (!Check1 (E.Item))
98                         return 8;
99
100                 if (Check2<int> (E.Item))
101                         return 9;
102                 
103                 Console.WriteLine ("OK");
104                 return 0;
105         }
106 }
107