Skip to content

Commit

Permalink
Prefer applicable methods from most derived type
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Jul 3, 2023
1 parent b7bef3b commit 89c7296
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Bonsai.Core/Expressions/ExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ class CallCandidate
internal static readonly CallCandidate Ambiguous = new CallCandidate();
internal static readonly CallCandidate None = new CallCandidate();
internal MethodBase method;
internal Type declaringType;
internal Expression[] arguments;
internal bool generic;
internal bool expansion;
Expand Down Expand Up @@ -818,6 +819,7 @@ static CallCandidate OverloadResolution(IEnumerable<MethodBase> methods, params
return new CallCandidate
{
method = method,
declaringType = method.DeclaringType,
arguments = callArguments,
generic = method.IsGenericMethod,
expansion = ParamExpansionRequired(parameters, argumentTypes),
Expand Down Expand Up @@ -853,6 +855,15 @@ static CallCandidate OverloadResolution(IEnumerable<MethodBase> methods, params
// skip self-test
if (i == j) continue;

// exclude self if declaring type is base type of other; and vice-versa
if (candidates[i].declaringType != candidates[j].declaringType)
{
if (candidates[i].declaringType.IsAssignableFrom(candidates[j].declaringType))
candidates[i].excluded = true;
else candidates[j].excluded = true;
continue;
}

// compare implicit type conversion
var comparison = CompareFunctionMember(
candidateParameters[i],
Expand Down

0 comments on commit 89c7296

Please sign in to comment.