Skip to content

method overloading fix for enum argument #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/runtime/methodbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,26 +309,38 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw,


if (clrtype != null) {
bool typematch = false;
if (pi[n].ParameterType != clrtype) {
IntPtr pytype = Converter.GetPythonTypeByAlias(pi[n].ParameterType);
pyoptype = Runtime.PyObject_Type(op);
Exceptions.Clear();
if (pyoptype != IntPtr.Zero) {
if (pytype != pyoptype) {
Runtime.Decref(pyoptype);
margs = null;
break;
typematch = false;
}
else {
typematch = true;
clrtype = pi[n].ParameterType;
}
}
else {
Runtime.Decref(pyoptype);
if (!typematch) {
// this takes care of enum values
TypeCode argtypecode = Type.GetTypeCode(pi[n].ParameterType);
TypeCode paramtypecode = Type.GetTypeCode(clrtype);
if (argtypecode == paramtypecode) {
typematch = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would comparing the type code of the parameter type and the clrtype be more appropriate here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonyroberts done! thanks for pointing out cleaner solution. I also added this "regression" test.

clrtype = pi[n].ParameterType;
}
}
Runtime.Decref(pyoptype);
if (!typematch) {
margs = null;
break;
}
Runtime.Decref(pyoptype);
}
else {
typematch = true;
clrtype = pi[n].ParameterType;
}
}
else {
Expand Down
6 changes: 6 additions & 0 deletions src/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ def testCorrectOverloadSelection(self):
atype(value1),
atype(value2)))

clr.AddReference("System.Runtime.InteropServices")
from System.Runtime.InteropServices import GCHandle, GCHandleType
from System import Array, Byte
CSArray = Array.CreateInstance(Byte, 1000)
handler = GCHandle.Alloc(CSArray, GCHandleType.Pinned)

def testGenericMethodOverloadSelection(self):
"""
Test explicit overload selection with generic methods.
Expand Down