@@ -86,16 +86,17 @@ internal void AddMethod(MethodBase m)
86
86
87
87
/// <summary>
88
88
/// Given a sequence of MethodInfo and a sequence of type parameters,
89
- /// return the MethodInfo that represents the matching closed generic.
89
+ /// return the MethodInfo(s) that represents the matching closed generic.
90
90
/// If unsuccessful, returns null and may set a Python error.
91
91
/// </summary>
92
- internal static MethodInfo ? MatchParameters ( MethodBase [ ] mi , Type [ ] ? tp )
92
+ internal static MethodInfo [ ] MatchParameters ( MethodBase [ ] mi , Type [ ] ? tp )
93
93
{
94
94
if ( tp == null )
95
95
{
96
- return null ;
96
+ return Array . Empty < MethodInfo > ( ) ;
97
97
}
98
98
int count = tp . Length ;
99
+ var result = new List < MethodInfo > ( ) ;
99
100
foreach ( MethodInfo t in mi )
100
101
{
101
102
if ( ! t . IsGenericMethodDefinition )
@@ -111,16 +112,14 @@ internal void AddMethod(MethodBase m)
111
112
{
112
113
// MakeGenericMethod can throw ArgumentException if the type parameters do not obey the constraints.
113
114
MethodInfo method = t . MakeGenericMethod ( tp ) ;
114
- Exceptions . Clear ( ) ;
115
- return method ;
115
+ result . Add ( method ) ;
116
116
}
117
- catch ( ArgumentException e )
117
+ catch ( ArgumentException )
118
118
{
119
- Exceptions . SetError ( e ) ;
120
119
// The error will remain set until cleared by a successful match.
121
120
}
122
121
}
123
- return null ;
122
+ return result . ToArray ( ) ;
124
123
}
125
124
126
125
@@ -381,9 +380,6 @@ public MismatchedMethod(Exception exception, MethodBase mb)
381
380
}
382
381
}
383
382
384
- var pynargs = ( int ) Runtime . PyTuple_Size ( args ) ;
385
- var isGeneric = false ;
386
-
387
383
MethodBase [ ] _methods ;
388
384
if ( info != null )
389
385
{
@@ -395,11 +391,19 @@ public MismatchedMethod(Exception exception, MethodBase mb)
395
391
_methods = GetMethods ( ) ;
396
392
}
397
393
398
- var argMatchedMethods = new List < MatchedMethod > ( _methods . Length ) ;
394
+ return Bind ( inst , args , kwargDict , _methods , matchGenerics : true ) ;
395
+ }
396
+
397
+ static Binding ? Bind ( BorrowedReference inst , BorrowedReference args , Dictionary < string , PyObject > kwargDict , MethodBase [ ] methods , bool matchGenerics )
398
+ {
399
+ var pynargs = ( int ) Runtime . PyTuple_Size ( args ) ;
400
+ var isGeneric = false ;
401
+
402
+ var argMatchedMethods = new List < MatchedMethod > ( methods . Length ) ;
399
403
var mismatchedMethods = new List < MismatchedMethod > ( ) ;
400
404
401
405
// TODO: Clean up
402
- foreach ( MethodBase mi in _methods )
406
+ foreach ( MethodBase mi in methods )
403
407
{
404
408
if ( mi . IsGenericMethod )
405
409
{
@@ -535,17 +539,17 @@ public MismatchedMethod(Exception exception, MethodBase mb)
535
539
536
540
return new Binding ( mi , target , margs , outs ) ;
537
541
}
538
- else if ( isGeneric && info == null && methodinfo != null )
542
+ else if ( matchGenerics && isGeneric )
539
543
{
540
544
// We weren't able to find a matching method but at least one
541
545
// is a generic method and info is null. That happens when a generic
542
546
// method was not called using the [] syntax. Let's introspect the
543
547
// type of the arguments and use it to construct the correct method.
544
548
Type [ ] ? types = Runtime . PythonArgsToTypeArray ( args , true ) ;
545
- MethodInfo ? mi = MatchParameters ( methodinfo , types ) ;
546
- if ( mi != null )
549
+ MethodInfo [ ] overloads = MatchParameters ( methods , types ) ;
550
+ if ( overloads . Length != 0 )
547
551
{
548
- return Bind ( inst , args , kw , mi , null ) ;
552
+ return Bind ( inst , args , kwargDict , overloads , matchGenerics : false ) ;
549
553
}
550
554
}
551
555
if ( mismatchedMethods . Count > 0 )
0 commit comments