Skip to content

Commit eaed5c2

Browse files
committed
fix object[] parameters taking precedence when should not in overload resolution
1 parent 61d1b7c commit eaed5c2

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ details about the cause of the failure
1919

2020
- Fix incorrect dereference of wrapper object in `tp_repr`, which may result in a program crash
2121
- Fix incorrect dereference in params array handling
22+
- Fix `object[]` parameters taking precedence when should not in overload resolution
2223

2324
## [2.5.0][] - 2020-06-14
2425

src/runtime/methodbinder.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ internal static int ArgPrecedence(Type t)
203203
return 3000;
204204
}
205205

206+
if (t.IsArray)
207+
{
208+
Type e = t.GetElementType();
209+
if (e == objectType)
210+
{
211+
return 2500;
212+
}
213+
return 100 + ArgPrecedence(e);
214+
}
215+
206216
TypeCode tc = Type.GetTypeCode(t);
207217
// TODO: Clean up
208218
switch (tc)
@@ -250,16 +260,6 @@ internal static int ArgPrecedence(Type t)
250260
return 40;
251261
}
252262

253-
if (t.IsArray)
254-
{
255-
Type e = t.GetElementType();
256-
if (e == objectType)
257-
{
258-
return 2500;
259-
}
260-
return 100 + ArgPrecedence(e);
261-
}
262-
263263
return 2000;
264264
}
265265

src/testing/methodtest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Runtime.InteropServices;
45

56
namespace Python.Test
@@ -84,7 +85,7 @@ public Type[] TestNullArrayConversion(Type[] v)
8485

8586
public static string[] TestStringParamsArg(params string[] args)
8687
{
87-
return args;
88+
return args.Concat(new []{"tail"}).ToArray();
8889
}
8990

9091
public static object[] TestObjectParamsArg(params object[] args)

src/tests/test_method.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,20 @@ def test_null_array_conversion():
206206
def test_string_params_args():
207207
"""Test use of string params."""
208208
result = MethodTest.TestStringParamsArg('one', 'two', 'three')
209-
assert result.Length == 3
210-
assert len(result) == 3, result
209+
assert result.Length == 4
210+
assert len(result) == 4, result
211211
assert result[0] == 'one'
212212
assert result[1] == 'two'
213213
assert result[2] == 'three'
214+
# ensures params string[] overload takes precedence over params object[]
215+
assert result[3] == 'tail'
214216

215217
result = MethodTest.TestStringParamsArg(['one', 'two', 'three'])
216-
assert len(result) == 3
218+
assert len(result) == 4
217219
assert result[0] == 'one'
218220
assert result[1] == 'two'
219221
assert result[2] == 'three'
222+
assert result[3] == 'tail'
220223

221224

222225
def test_object_params_args():

0 commit comments

Comments
 (0)