From 4692e68fe0b1fd3452783b32563fac0079efc955 Mon Sep 17 00:00:00 2001 From: omnicognate Date: Wed, 6 Apr 2016 15:39:45 +0100 Subject: [PATCH] Fix for #200 - check for params array args correctly --- src/runtime/methodbinder.cs | 6 ++---- src/testing/methodtest.cs | 8 ++++++++ src/tests/test_method.py | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index b73e596bd..943f9da04 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -269,10 +269,8 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, defaultArgList.Add((object)pi[v].DefaultValue); } } else if ((pynargs > clrnargs) && (clrnargs > 0) && - (pi[clrnargs-1].ParameterType.IsArray)) { - // The last argument of the mananged functions seems to - // accept multiple arguments as a array. Hopefully it's a - // spam(params object[] egg) style method + Attribute.IsDefined(pi[clrnargs-1], typeof(ParamArrayAttribute))) { + // This is a spam(params object[] egg) style method match = true; arrayStart = clrnargs - 1; } diff --git a/src/testing/methodtest.cs b/src/testing/methodtest.cs index 8bda5215f..28ef8f553 100644 --- a/src/testing/methodtest.cs +++ b/src/testing/methodtest.cs @@ -117,6 +117,14 @@ public static bool TestStringRefParams (string s, ref string s1) { return true; } + public static bool TestNonParamsArrayInLastPlace(int i1, int[] i2) { + return false; + } + + public static bool TestNonParamsArrayInLastPlace(int i1, int i2, int i3) { + return true; + } + public static bool TestValueOutParams (string s, out int i1) { i1 = 42; return true; diff --git a/src/tests/test_method.py b/src/tests/test_method.py index 3f9c1fdff..ca5729a43 100644 --- a/src/tests/test_method.py +++ b/src/tests/test_method.py @@ -304,6 +304,10 @@ def testValueParamsArgs(self): self.assertTrue(result[1] == 2) self.assertTrue(result[2] == 3) + def testNonParamsArrayInLastPlace(self): + """Test overload resolution with of non-"params" array as last parameter.""" + result = MethodTest.TestNonParamsArrayInLastPlace(1, 2, 3) + self.assertTrue(result) def testStringOutParams(self): """Test use of string out-parameters."""