8000 Fix and test for overload resolution when last parameter takes a non-"params" array by omnicognate · Pull Request #201 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Fix and test for overload resolution when last parameter takes a non-"params" array #201

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
Apr 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed 8000 to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/runtime/methodbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/testing/methodtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/tests/test_method.py
4A31
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ def testValueParamsArgs(self):
self.assertTrue(result[1] == 2)
self.assertTrue(result[2] == 3)

def testNonParamsArrayInLastPlace(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

How about tests for the cases with params args & arrays?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean the case where there is a params keyword. If so, I believe that's covered by existing tests, eg. testObjectParamsArgs

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean don't you need to add in c# and check in python tests for the
following case below?

public static bool TestNonParamsArrayInLastPlace(int i1, params int[] ints)
{ return false; }

Maybe boolean return value needs to be changed to integer, since then there
are 3 overloaded cases.

On Wed, Apr 6, 2016 at 10:47 AM, omnicognate notifications@github.com
wrote:

In src/tests/test_method.py
#201 (comment):

@@ -304,6 +304,10 @@ def testValueParamsArgs(self):
self.assertTrue(result[1] == 2)
self.assertTrue(result[2] == 3)

  • def testNonParamsArrayInLastPlace(self):

Do you mean the case where there is a params keyword. If so, I believe
that's covered by existing tests, eg. testObjectParamsArgs


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/pythonnet/pythonnet/pull/201/files/4117162e2e98a0d2458c067ac7ea4b69e9a5d8e2#r58729780

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tried it, but C# won't let me have both

TestNonParamsArrayInLastPlace(int i1, params int[] ints)

and

TestNonParamsArrayInLastPlace(int i1, int[] ints)

It says they have the same name and parameter types, error CS0111.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense - no more questions! the answer as to why both are not allowed
is given here: http://stackoverflow.com/a/7580295/2230844

On Wed, Apr 6, 2016 at 11:29 AM, omnicognate notifications@github.com
wrote:

In src/tests/test_method.py
#201 (comment):

@@ -304,6 +304,10 @@ def testValueParamsArgs(self):
self.assertTrue(result[1] == 2)
self.assertTrue(result[2] == 3)

  • def testNonParamsArrayInLastPlace(self):

I just tried it, but C# won't let me have both

TestNonParamsArrayInLastPlace(int i1, params int[] ints)

and

TestNonParamsArrayInLastPlace(int i1, int[] ints)

It says they have the same name and parameter types, error CS0111.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
https://github.com/pythonnet/pythonnet/pull/201/files/4117162e2e98a0d2458c067ac7ea4b69e9a5d8e2#r58737494

"""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."""
Expand Down
0