2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / tests / test-78.cs
blob3787fe6b9e2bb9f65d41f4d03faca181c37a5f9c
1 //
2 // This test exhibits an old bug where we did not
3 // go into the underlying type for an enumeration, and
4 // hence implicit and explicit casts were not working when
5 // they were going from a type to an enum
6 //
8 namespace N1
9 {
10 public enum A
12 A_1, A_2, A_3
15 public class B
17 static bool ShortCasting ()
19 short i = 0;
20 N1.A a = N1.A.A_1;
22 i = (short) a; //<- crash
23 a = (N1.A)i;//<- used to fail, can't convert
25 if (a != N1.A.A_1)
26 return false;
27 return true;
30 static bool IntCasting ()
32 int i = 0;
33 N1.A a = N1.A.A_1;
35 i = (int) a;//<- works fine
36 a = (N1.A)i;//<- used to fail, can't convert
38 if (a != N1.A.A_1)
39 return false;
40 return true;
43 static int Main ()
45 if (!IntCasting ())
46 return 1;
47 if (!ShortCasting ())
48 return 2;
49 return 0;