Skip to content

Syntax error calling overloaded method in context object including Func<> parameter #154

Description

@antong93

The expression evaluator fails to identify and call the correct instance of an overloaded method in a context object when a Func<>-parameter is included. Instead, the top implemented instance of the overloaded method with correct number of parameters is being called, which causes an ExpressionEvaluatorSyntaxErrorException since the Func<>-parameter isn't convertible to its data type.

In the example below the evaluator will try to convert the Func<> x => true to a string.

However, this works fine when Hello(Func<string, bool> filter) is implemented above Hello(string name). This hasn't always been a requirement though, for example this error doesn't occur in version 1.4.21. I don't know in which version this error first occured.

[EXAMPLE]

void Main()
{
	var evaluator = new  CodingSeb.ExpressionEvaluator.ExpressionEvaluator {
		Context = new Test()
	};
	var result = evaluator.Evaluate("Hello(x => true)");
}

public class Test 
{
	public string Hello(string name) {
		return $"Hello {name}!";
	}
	
	public string Hello(Func<string, bool> filter) {
		return $"Hello. This method will not be reached!";
	}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions