Skip to content

Commit 4692e68

Browse files
omnicognatetom
authored and
tom
committed
Fix for #200 - check for params array args correctly
1 parent bc414e1 commit 4692e68

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/runtime/methodbinder.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,8 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
269269
defaultArgList.Add((object)pi[v].DefaultValue);
270270
}
271271
} else if ((pynargs > clrnargs) && (clrnargs > 0) &&
272-
(pi[clrnargs-1].ParameterType.IsArray)) {
273-
// The last argument of the mananged functions seems to
274-
// accept multiple arguments as a array. Hopefully it's a
275-
// spam(params object[] egg) style method
272+
Attribute.IsDefined(pi[clrnargs-1], typeof(ParamArrayAttribute))) {
273+
// This is a spam(params object[] egg) style method
276274
match = true;
277275
arrayStart = clrnargs - 1;
278276
}

src/testing/methodtest.cs

+8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public static bool TestStringRefParams (string s, ref string s1) {
117117
return true;
118118
}
119119

120+
public static bool TestNonParamsArrayInLastPlace(int i1, int[] i2) {
121+
return false;
122+
}
123+
124+
public static bool TestNonParamsArrayInLastPlace(int i1, int i2, int i3) {
125+
return true;
126+
}
127+
120128
public static bool TestValueOutParams (string s, out int i1) {
121129
i1 = 42;
122130
return true;

src/tests/test_method.py

+4
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ def testValueParamsArgs(self):
304304
self.assertTrue(result[1] == 2)
305305
self.assertTrue(result[2] == 3)
306306

307+
def testNonParamsArrayInLastPlace(self):
308+
"""Test overload resolution with of non-"params" array as last parameter."""
309+
result = MethodTest.TestNonParamsArrayInLastPlace(1, 2, 3)
310+
self.assertTrue(result)
307311

308312
def testStringOutParams(self):
309313
"""Test use of string out-parameters."""

0 commit comments

Comments
 (0)