Move Enum and CorElementType to shared (dotnet/coreclr#23177)
[mono-project.git] / mcs / tests / test-78.cs
blobe247b61507e530b4f03255d48b9192de7331a7c5
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 public static int Main ()
45 if (!IntCasting ())
46 return 1;
47 if (!ShortCasting ())
48 return 2;
49 return 0;