Skip to content

Commit f41afc4

Browse files
authored
Don't list extension methods multiple times (#1620)
* Don't return same method multiple times * Deduplicate in PythonExtensionBinder instead * Re-enable test * Disable on .NET Core 2.1
1 parent ca06ddb commit f41afc4

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public PythonExtensionBinder(PythonBinder binder, ExtensionMethodSet extensionMe
2323
public override MemberGroup GetMember(MemberRequestKind actionKind, Type type, string name) {
2424
var res = base.GetMember(actionKind, type, name);
2525
if (res.Count == 0) {
26-
List<MemberTracker> trackers = new List<MemberTracker>();
26+
// GetExtensionMethods may return duplicate MethodInfo so use a HashSet - https://github.com/IronLanguages/ironpython2/issues/810
27+
HashSet<MemberTracker> trackers = null;
2728

2829
foreach (var method in _extMethodSet.GetExtensionMethods(name)) {
2930
var parameters = method.GetParameters();
@@ -34,11 +35,11 @@ public override MemberGroup GetMember(MemberRequestKind actionKind, Type type, s
3435
var paramType = parameters[0].ParameterType;
3536

3637
if (IsApplicableExtensionMethod(type, paramType)) {
37-
trackers.Add(MemberTracker.FromMemberInfo(method, paramType));
38+
(trackers ??= new HashSet<MemberTracker>()).Add(MemberTracker.FromMemberInfo(method, paramType));
3839
}
3940
}
4041

41-
if (trackers.Count > 0) {
42+
if (trackers is not null) {
4243
return new MemberGroup(trackers.ToArray());
4344
}
4445
}

Tests/test_cliclass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,9 +1872,9 @@ class MyXamlRootObject(XamlTestObject):
18721872
finally:
18731873
os.unlink(fname)
18741874

1875-
@unittest.skipIf(is_netcoreapp, "https://github.com/IronLanguages/ironpython2/issues/810")
1875+
@unittest.skipIf(is_netcoreapp21, "TODO: figure out")
18761876
def test_extension_methods(self):
1877-
import clr, imp, os
1877+
import clr, os
18781878
if is_netcoreapp:
18791879
clr.AddReference('System.Linq')
18801880
else:

0 commit comments

Comments
 (0)