Skip to content

Commit 66691ff

Browse files
denfromufaden-run-ai
denfromufa
authored andcommitted
method overloading fix for enum argument
1 parent 6e4c8bb commit 66691ff

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/runtime/methodbinder.cs

+18-6
Original file line numberDiff line numberDiff line change
@@ -309,26 +309,38 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,
309309

310310

311311
if (clrtype != null) {
312+
bool typematch = false;
312313
if (pi[n].ParameterType != clrtype) {
313314
IntPtr pytype = Converter.GetPythonTypeByAlias(pi[n].ParameterType);
314315
pyoptype = Runtime.PyObject_Type(op);
315316
Exceptions.Clear();
316317
if (pyoptype != IntPtr.Zero) {
317318
if (pytype != pyoptype) {
318-
Runtime.Decref(pyoptype);
319-
margs = null;
320-
break;
319+
typematch = false;
321320
}
322321
else {
322+
typematch = true;
323323
clrtype = pi[n].ParameterType;
324324
}
325325
}
326-
else {
327-
Runtime.Decref(pyoptype);
326+
if (!typematch) {
327+
// this takes care of enum values
328+
TypeCode argtypecode = Type.GetTypeCode(pi[n].ParameterType);
329+
TypeCode paramtypecode = Type.GetTypeCode(clrtype);
330+
if (argtypecode == paramtypecode) {
331+
typematch = true;
332+
clrtype = pi[n].ParameterType;
333+
}
334+
}
335+
Runtime.Decref(pyoptype);
336+
if (!typematch) {
328337
margs = null;
329338
break;
330339
}
331-
Runtime.Decref(pyoptype);
340+
}
341+
else {
342+
typematch = true;
343+
clrtype = pi[n].ParameterType;
332344
}
333345
}
334346
else {

src/tests/test_generic.py

+6
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ def testCorrectOverloadSelection(self):
375375
atype(value1),
376376
atype(value2)))
377377

378+
clr.AddReference("System.Runtime.InteropServices")
379+
from System.Runtime.InteropServices import GCHandle, GCHandleType
380+
from System import Array, Byte
381+
CSArray = Array.CreateInstance(Byte, 1000)
382+
handler = GCHandle.Alloc(CSArray, GCHandleType.Pinned)
383+
378384
def testGenericMethodOverloadSelection(self):
379385
"""
380386
Test explicit overload selection with generic methods.

0 commit comments

Comments
 (0)