Skip to content

Commit

Permalink
MethodHasPriority: improve resolution (#210)
Browse files Browse the repository at this point in the history
MethodHasPriority: use promoted parameters when the method's argument type is an inferred generic type.
Fixes #203
  • Loading branch information
metoule authored Dec 13, 2021
1 parent dcc633f commit 6e7ef1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/DynamicExpresso.Core/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2363,11 +2363,11 @@ private static bool MethodHasPriority(Expression[] args, MethodData method, Meth
var methodParamType = GetParameterType(methodParam);
var otherMethodParamType = GetParameterType(otherMethodParam);

if (arg is InterpreterExpression)
{
if (methodParamType.ContainsGenericParameters)
methodParamType = method.PromotedParameters[i].Type;

if (otherMethodParamType.ContainsGenericParameters)
otherMethodParamType = otherMethod.PromotedParameters[i].Type;
}

var c = CompareConversions(arg.Type, methodParamType, otherMethodParamType);
if (c < 0)
Expand Down
12 changes: 12 additions & 0 deletions test/DynamicExpresso.UnitTest/GithubIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@ public void GitHub_Issue_191()
}

[Test]
public void GitHub_Issue_203()
{
var target = new Interpreter();
target.Reference(typeof(Utils));

var list = new[] { 1, 2, 3 };

var listInt = target.Eval<List<int>>("Utils.Array(list)", new Parameter("list", list));
Assert.AreEqual(Utils.Array(list), listInt);
}

[Test]
public void GitHub_Issue_205_Property_on_nullable()
{
var interpreter = new Interpreter();
Expand Down

0 comments on commit 6e7ef1e

Please sign in to comment.