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

Improve MethodHasPriority algorithm #193

Merged
merged 4 commits into from
Nov 25, 2021
Merged

Conversation

metoule
Copy link
Contributor

@metoule metoule commented Nov 24, 2021

This is mainly a fix for #191, but I also took the opportunity to improve the support of params arrays, to more closely match the C# specification.

For example, the following method calls are now properly resolved:

public static class Utils
{
  public static int WithParamsArray(params int[] i) => 3;
  public static int WithParamsArray(int i, params int[] j) => 4;
  public static int WithParamsArray(int i, int j) => 5;
}

var target = new Interpreter();
target.Reference(typeof(Utils));

var arr = new int[] { 2 };
target.SetVariable("arr", arr);

Assert.AreEqual(3, target.Eval("Utils.WithParamsArray(arr)"));
Assert.AreEqual(4, target.Eval("Utils.WithParamsArray(1)")); // improper call to int WithParamsArray(params int[] i)
Assert.AreEqual(4, target.Eval("Utils.WithParamsArray(1, arr)"));
Assert.AreEqual(5, target.Eval("Utils.WithParamsArray(1, 2)"));
Assert.AreEqual(4, target.Eval("Utils.WithParamsArray(1, 2, 3)")); // resolution failure 
Assert.AreEqual(4, target.Eval("Utils.WithParamsArray(1, 2, 3, 4)")); // resolution failure 

@davideicardi
Copy link
Member

LGTM!

@metoule metoule merged commit 862aa8a into dynamicexpresso:master Nov 25, 2021
@metoule metoule deleted the fix_191 branch November 25, 2021 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants