Make improvments after code review:
authorJosh Peterson <petersonjm1@gmail.com>
Tue, 30 Aug 2016 14:46:02 +0000 (10:46 -0400)
committerJosh Peterson <petersonjm1@gmail.com>
Tue, 30 Aug 2016 14:46:02 +0000 (10:46 -0400)
* Use mono_set_pending_exception instead of mono_raise_exception
* Make the test an nunit test instead of a runtime test.

mcs/class/corlib/Test/System/DelegateTest.cs
mono/metadata/icall.c
mono/tests/Makefile.am
mono/tests/delegate-argument-exception.cs [deleted file]

index e1d95dc93f00f563a4a7415708b3714d5a107a4f..ba664353ab9e0056492a1ae525057969609af25e 100644 (file)
@@ -1445,6 +1445,18 @@ namespace MonoTests.System
                        var del = Delegate.Remove (del1, del2);
                }
 
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void CreateDelegateThrowsAnArgumentExceptionWhenCalledWithAnOpenGeneric()
+               {
+                       var m = GetType().GetMethod("AnyGenericMethod");
+                       Delegate.CreateDelegate(typeof(Action), this, m);
+               }
+
+               public void AnyGenericMethod<T>()
+               {
+               }
+
                static bool Int32D2 (int x, int y)
                {
                        return (x & y) == y; 
index 74caa8406ab83e3a976452412569f396eff25c2a..e1af074c4b459028a909b6e5e75165829ebe74a6 100644 (file)
@@ -6238,8 +6238,10 @@ ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, Mon
        }
 
        if (sig->generic_param_count && method->wrapper_type == MONO_WRAPPER_NONE) {
-               if (!method->is_inflated)
-                       mono_raise_exception(mono_get_exception_argument("method", " Cannot bind to the target method because its signature differs from that of the delegate type"));
+               if (!method->is_inflated) {
+                       mono_set_pending_exception(mono_get_exception_argument("method", " Cannot bind to the target method because its signature differs from that of the delegate type"));
+                       return NULL;
+               }
        }
 
        delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
index ed8172c51edc2f9a09b5060aedcfc19502f16569..b4d9d0ad8666a1939bfd5a5ef04657a2832a2859 100644 (file)
@@ -326,7 +326,6 @@ BASE_TEST_CS_SRC_UNIVERSAL=         \
        bug-323114.cs           \
        bug-Xamarin-5278.cs     \
        interlocked.cs          \
-       delegate-argument-exception.cs  \
        delegate-async-exit.cs  \
        delegate-delegate-exit.cs       \
        delegate-exit.cs        \
diff --git a/mono/tests/delegate-argument-exception.cs b/mono/tests/delegate-argument-exception.cs
deleted file mode 100644 (file)
index 7fcef5b..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-
-class Test {
-       public static int Main () {
-               return new Test().CallCreateDelegate();
-       }
-
-       public int CallCreateDelegate() {
-               try     {
-                       var m = typeof(Test).GetMethod("Foo");
-                       var a = (Action) Delegate.CreateDelegate(typeof(Action), this, m);
-                       a();
-               }
-               catch (ArgumentException) {
-                       return 0;
-               }
-
-               return 1;
-       }
-
-       public void Foo<T>()
-       {
-       }
-}
\ No newline at end of file