dadhi/FastExpressionCompiler

FastExpressionCompiler[v3.3.4] gives incorrect results in some linq operations

abbasc52 opened this issue · 3 comments

Hi I recently updated to v3.3.4 and it seems to give incorrect results in some scenarios:
Specifically if there is a linq operation of comparing with some input value, it gives wrong results.

Here is a dotnetfiddle example of it - https://dotnetfiddle.net/sDIkWg

Reverting to v3.3.3 fixes this issue.

I can reproduce this issue for double input parameter as well as int, haven't tried other types

dadhi commented

@abbasc52 Hi. Interesting case. First time see the System.Linq.Dynamic package in the wild.
I will check it.

// Dynamic LINQ
// Doc: https://linq-dynamic.net/parse-lambda


using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Linq.Dynamic.Core;
using System.Linq.Dynamic.Core.Parser;
using System.Linq.Dynamic.Core.CustomTypeProviders;
using System.ComponentModel.DataAnnotations;
using FastExpressionCompiler;

public class Program
{

	
	public static void Main()
	{
		ParameterExpression x = Expression.Parameter(typeof(double), "threshold");
        ParameterExpression y = Expression.Parameter(typeof(List<double>), "mylist");

        var symbols = new[] { x, y };

        Expression body = new ExpressionParser(symbols, "mylist.Where(c => c > threshold).FirstOrDefault()", null, new ParsingConfig()).Parse(typeof(double));

        LambdaExpression e = Expression.Lambda(body, symbols);

		var normalCompile = e.Compile();
		var fastCompile = e.CompileFast();
		
        var result1 = normalCompile.DynamicInvoke(new object[]{ 3.0, new List<double>{1.0,2.0,3.0,4.0,5.0 } });
		Console.Write("Normal Compile Result:");
        Console.WriteLine(result1);
		
		 var result2 = fastCompile.DynamicInvoke(new object[]{ 3.0, new List<double>{1.0,2.0,3.0,4.0,5.0 } });
		Console.Write("Fast Compile Result:");
        Console.WriteLine(result2);
	}
}
dadhi commented

@abbasc52 The issue is appears to be fixed in the v3.4.0-preview-01 https://dotnetfiddle.net/xVvIHi