merge from trunk revisions 58933, 58935, 58936
[mono.git] / mcs / tests / test-305.cs
1 // Compiler options: -unsafe
2
3 using System;
4 using System.Runtime.InteropServices;
5
6 using S = A.T;
7
8 class A
9 {
10         [StructLayout (LayoutKind.Sequential)]
11         struct T { int x; }
12
13         public class B
14         {
15                 [StructLayout (LayoutKind.Sequential)]
16                 struct S { int x; int y; }
17                 S s;
18
19                 public B () {
20                         string error = "";
21
22                         unsafe {
23                                 if (typeof (S *).GetElementType () != typeof (A.B.S))
24                                         error += " composed cast (pointer),";
25
26                                 if (sizeof (S) != sizeof (A.B.S))
27                                         error += " sizeof,";
28
29                                 S *p1 = stackalloc S [1];
30
31                                 if ((*p1).GetType () != typeof (A.B.S))
32                                         error += " local declaration, 'stackalloc' keyword,";
33
34                                 fixed (S *p2 = &s) {
35                                         if ((*p2).GetType () != typeof (A.B.S))
36                                                 error += " class declaration, 'fixed' statement,";
37                                 }
38                         }
39
40                         if (error.Length != 0)
41                                 throw new Exception ("The following couldn't resolve S as A+B+S:" + error);
42                 }
43         }
44
45         public static void Main()
46         {
47                 object o = new A.B();
48         }
49 }