Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4133927

Browse files
authored
Ensure that param-array matching works correctly (#1304)
We can match n Python parameters to exactly n+1 C# parameters of whichthe last one is a param-array.Fixes#1302.There are still two cases that are not covered.
1 parent24c5af3 commit4133927

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-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,outisNewReference);
515+
op=HandleParamsArray(args,arrayStart,pyArgCount,outisNewReference);
516516
}
517517
else
518518
{
@@ -652,7 +652,7 @@ static bool MatchesArgumentCount(int positionalArgumentCount, ParameterInfo[] pa
652652
{
653653
match=true;
654654
}
655-
elseif(positionalArgumentCount<parameters.Length)
655+
elseif(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-
elseif(!paramsArray)
680+
elseif(!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+
publicclassMultipleConstructorsTest
53+
{
54+
publicstringvalue;
55+
publicType[]type;
56+
57+
publicMultipleConstructorsTest()
58+
{
59+
value="";
60+
type=newType[1]{null};
61+
}
62+
63+
publicMultipleConstructorsTest(strings,paramsType[]tp)
64+
{
65+
value=s;
66+
type=tp;
67+
}
68+
}
5169
}

‎src/testing/methodtest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,16 @@ public static string DefaultParamsWithOverloading(int a = 5, int b = 6, int c =
703703
{
704704
return$"{a}{b}{c}{d}XXX";
705705
}
706+
707+
publicstaticstringParamsArrayOverloaded(inti=1)
708+
{
709+
return"without params-array";
710+
}
711+
712+
publicstaticstringParamsArrayOverloaded(inti,paramsint[]paramsArray)
713+
{
714+
return"with params-array";
715+
}
706716
}
707717

708718

‎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
assertisinstance(ob.value,System.Exception)
47+
48+
49+
deftest_multiple_constructor():
50+
fromPython.TestimportMultipleConstructorsTest
51+
importSystem
52+
53+
# Test parameterless
54+
ob=MultipleConstructorsTest()
55+
assertob.value==""

‎src/tests/test_method.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,3 +1188,36 @@ def test_keyword_arg_method_resolution():
11881188
ob=MethodArityTest()
11891189
assertob.Foo(1,b=2)=="Arity 2"
11901190

1191+
deftest_params_array_overload():
1192+
res=MethodTest.ParamsArrayOverloaded()
1193+
assertres=="without params-array"
1194+
1195+
res=MethodTest.ParamsArrayOverloaded(1)
1196+
assertres=="without params-array"
1197+
1198+
res=MethodTest.ParamsArrayOverloaded(i=1)
1199+
assertres=="without params-array"
1200+
1201+
res=MethodTest.ParamsArrayOverloaded(1,2)
1202+
assertres=="with params-array"
1203+
1204+
res=MethodTest.ParamsArrayOverloaded(1,2,3)
1205+
assertres=="with params-array"
1206+
1207+
res=MethodTest.ParamsArrayOverloaded(1,paramsArray=[])
1208+
assertres=="with params-array"
1209+
1210+
res=MethodTest.ParamsArrayOverloaded(1,i=1)
1211+
assertres=="with params-array"
1212+
1213+
res=MethodTest.ParamsArrayOverloaded(1,2,3,i=1)
1214+
assertres=="with params-array"
1215+
1216+
# These two cases are still incorrectly failing:
1217+
1218+
# res = MethodTest.ParamsArrayOverloaded(1, 2, i=1)
1219+
# assert res == "with params-array"
1220+
1221+
# res = MethodTest.ParamsArrayOverloaded(paramsArray=[], i=1)
1222+
# assert res == "with params-array"
1223+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp