Skip to content
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

Don't list extension methods multiple times. #836

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public PythonExtensionBinder(PythonBinder binder, ExtensionMethodSet extensionMe
public override MemberGroup GetMember(MemberRequestKind actionKind, Type type, string name) {
var res = base.GetMember(actionKind, type, name);
if (res.Count == 0) {
List<MemberTracker> trackers = new List<MemberTracker>();
HashSet<MemberTracker> trackers = new HashSet<MemberTracker>();

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

if (IsApplicableExtensionMethod(type, paramType)) {
trackers.Add(MemberTracker.FromMemberInfo(method, paramType));
(trackers ??= new HashSet<MemberTracker>()).Add(MemberTracker.FromMemberInfo(method, paramType));
}
}

if (trackers.Count > 0) {
if (trackers is not null) {
return new MemberGroup(trackers.ToArray());
}
}
Expand Down
9 changes: 6 additions & 3 deletions Src/IronPython/Runtime/ExtensionMethodSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,18 @@ public IEnumerable<MethodInfo> GetExtensionMethods(string/*!*/ name) {
lock (this) {
EnsureLoaded();

var yieldedMethods = new HashSet<MethodInfo>();

foreach (var keyValue in _loadedAssemblies) {
AssemblyLoadInfo info = keyValue.Value;

Debug.Assert(info.Types != null);
foreach (var type in info.Types) {
List<MethodInfo> methods;
if (type.ExtensionMethods.TryGetValue(name, out methods)) {
if (type.ExtensionMethods.TryGetValue(name, out var methods)) {
foreach (var method in methods) {
yield return method;
if (yieldedMethods.Add(method)) {
yield return method;
}
}
}
}
Expand Down
Loading