From a9a9b650c7fcf14876856b0b2afc0299117cfd3c Mon Sep 17 00:00:00 2001 From: metoule Date: Fri, 10 Dec 2021 09:27:56 +0100 Subject: [PATCH 1/2] Add test. --- test/DynamicExpresso.UnitTest/GithubIssues.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/DynamicExpresso.UnitTest/GithubIssues.cs b/test/DynamicExpresso.UnitTest/GithubIssues.cs index ab5626a7..80ee86fc 100644 --- a/test/DynamicExpresso.UnitTest/GithubIssues.cs +++ b/test/DynamicExpresso.UnitTest/GithubIssues.cs @@ -398,6 +398,19 @@ public void GitHub_Issue_191() Assert.IsNotNull(result); } + [Test] + public void GitHub_Issue_203() + { + var target = new Interpreter(); + target.Reference(typeof(Utils)); + + var list = new[] { 1, 2, 3 }; + + var listInt = target.Eval>("Utils.Array(list)", new Parameter("list", list)); + Assert.AreEqual(Utils.Array(list), listInt); + } + + public class Utils { public static List Array(IEnumerable collection) => new List(collection); From 4acf3d3aa48de4b5ffcbb930eab9913f16cb5191 Mon Sep 17 00:00:00 2001 From: metoule Date: Sun, 12 Dec 2021 20:16:13 +0100 Subject: [PATCH 2/2] MethodHasPriority: use promoted parameters when the method's argument type is an inferred generic type. Fixes #203 --- src/DynamicExpresso.Core/Parsing/Parser.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DynamicExpresso.Core/Parsing/Parser.cs b/src/DynamicExpresso.Core/Parsing/Parser.cs index ce9a04f4..e16a3f30 100644 --- a/src/DynamicExpresso.Core/Parsing/Parser.cs +++ b/src/DynamicExpresso.Core/Parsing/Parser.cs @@ -2340,11 +2340,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)