[jit] Fix the saving of the 'cfg->ret_var_set' flag when inlining, it was set to...
[mono.git] / mcs / tests / dtest-error-01.cs
1 // Compiler options: -unsafe
2
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Reflection;
7 using Microsoft.CSharp.RuntimeBinder;
8
9 class Helper
10 {
11         public unsafe static int* Foo (int i)
12         {
13                 return null;
14         }
15 }
16
17 class Tester
18 {
19 #pragma warning disable 169
20         void NonInvocable ()
21         {
22                 AssertError (
23                         () => {
24                                 dynamic d = 1;
25                                 d ();
26                         }, "Cannot invoke a non-delegate type");
27         }
28         
29         void Using_1 ()
30         {
31                 AssertError (
32                         () => {
33                                 using (dynamic d = 1) { }
34                         }, "Cannot implicitly convert type 'int' to 'System.IDisposable'");
35         }
36         
37         void Unsafe_1 ()
38         {
39                 dynamic d = 1;
40                 AssertError (
41                         () => Helper.Foo (d),
42                         "Dynamic calls cannot be used in conjunction with pointers");
43         }
44         
45         void NullableConversion ()
46         {
47                 dynamic d = 1;
48                 AssertError (
49                         () => {
50                                 dynamic b = false;
51                                 byte? b2 = null;
52                                 b &= b2;
53                         }, "Operator '&=' cannot be applied to operands of type 'bool' and 'byte?'");
54         }
55         
56 #pragma warning restore 169
57         
58         static void AssertError (Action a, string msg)
59         {
60                 try {
61                         a ();
62                 } catch (RuntimeBinderException e) {
63                         if (e.Message != msg)
64                                 throw new ApplicationException ("Expected error message: " + e.Message);
65                         
66                         return;
67                 }
68                 
69                 throw new ApplicationException ("Expected error");
70         }
71
72         static bool RunTest (MethodInfo test)
73         {
74                 Console.Write ("Running test {0, -25}", test.Name);
75                 try {
76                         test.Invoke (new Tester (), null);
77                         Console.WriteLine ("OK");
78                         return true;
79                 } catch (Exception e) {
80                         Console.WriteLine ("FAILED");
81                         Console.WriteLine (e.InnerException.Message);
82                         return false;
83                 }
84         }
85
86         public static int Main ()
87         {
88                 var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
89                                         where test.GetParameters ().Length == 0
90                                         orderby test.Name
91                                         select RunTest (test);
92
93                 int failures = tests.Count (a => !a);
94                 Console.WriteLine (failures + " tests failed");
95                 return failures;
96         }
97 }