Skip to content

Commit 001aeec

Browse files
committed
Ensure that param-array matching works correctly
We can match n Python parameters to exactly n+1 C# parameters of which the last one is a param-array. Fixes #1302.
1 parent c692491 commit 001aeec

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/runtime/methodbinder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ static object[] TryConvertArguments(ParameterInfo[] pi, bool paramsArray,
512512
{
513513
if(arrayStart == paramIndex)
514514
{
515-
op = HandleParamsArray(args, arrayStart, pyArgCount, out isNewReference);
515+
op = HandleParamsArray(args, arrayStart, pyArgCount, out isNewReference);
516516
}
517517
else
518518
{
@@ -652,7 +652,7 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa
652652
{
653653
match = true;
654654
}
655-
else if (positionalArgumentCount < parameters.Length)
655+
else if (positionalArgumentCount < parameters.Length && (!paramsArray || positionalArgumentCount == parameters.Length - 1))
656656
{
657657
// every parameter past 'positionalArgumentCount' must have either
658658
// a corresponding keyword argument or a default parameter
@@ -677,7 +677,7 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa
677677
defaultArgList.Add(parameters[v].GetDefaultValue());
678678
defaultsNeeded++;
679679
}
680-
else if(!paramsArray)
680+
else if (!paramsArray)
681681
{
682682
match = false;
683683
}

src/testing/constructortests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,22 @@ public SubclassConstructorTest(Exception v)
4848
value = v;
4949
}
5050
}
51+
52+
public class MultipleConstructorsTest
53+
{
54+
public string value;
55+
public Type[] type;
56+
57+
public MultipleConstructorsTest()
58+
{
59+
value = "";
60+
type = new Type[1] { null };
61+
}
62+
63+
public MultipleConstructorsTest(string s, params Type[] tp)
64+
{
65+
value = s;
66+
type = tp;
67+
}
68+
}
5169
}

src/tests/test_constructors.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ class Sub(System.Exception):
4444
instance = Sub()
4545
ob = SubclassConstructorTest(instance)
4646
assert isinstance(ob.value, System.Exception)
47+
48+
49+
def test_multiple_constructor():
50+
from Python.Test import MultipleConstructorsTest
51+
import System
52+
53+
# Test parameterless
54+
ob = MultipleConstructorsTest()
55+
assert ob.value == ""

0 commit comments

Comments
 (0)