2010-05-27 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / tests / gtest-117.cs
1 // Compiler options: -warnaserror
2
3 using System;
4
5 public interface IFoo<T>
6 { }
7
8 public class Foo<T>
9 {
10         public static bool Test (T x)
11         {
12                 return x is IFoo<T>;
13         }
14         
15         public static bool Test ()
16         {
17                 T t = default (T);
18                 return t is int;
19         }
20         
21         public static bool TestB ()
22         {
23                 T t = default (T);
24                 return t is int?;
25         }
26 }
27
28 class Y<T> where T : struct
29 {
30         public bool Foo ()
31         {
32                 object o = null;
33                 return o is System.Nullable <T>;
34         }
35 }
36
37 class X
38 {
39         public static bool TestA (object o)
40         {
41                 return o is int?;
42         }
43         
44         public static bool TestB<T> (T o)
45         {
46                 return o is int[];
47         }
48         
49         public static int TestC ()
50         {
51                 int? i = null;
52                 if (i is int) {
53                                 return (int) i;
54                 }
55                 
56                 return 3;
57         }
58         
59         static int Main ()
60         {
61                 if (Foo<int>.Test (3))
62                         return 1;
63                 
64                 if (!Foo<int>.Test())
65                         return 2;
66                 
67                 // False expected int? != null
68                 if (Foo<int?>.TestB())
69                         return 3;
70
71                 int? i = 0;
72                 if (!TestA(i))
73                         return 4;
74                 
75                 int[] a = new int[0];
76                 if (!TestB(a))
77                         return 5;
78                 
79                 if (TestC () != 3)
80                         return 6;
81                 
82                 Console.WriteLine ("OK");
83                 return 0;
84         }
85 }
86