dadhi / FastExpressionCompiler

Fast Compiler for C# Expression Trees and the lightweight LightExpression alternative. Diagnostic and code generation tools for the expressions.
MIT License
1.16k stars 82 forks source link

Comparisons with nullable types #380

Closed celi closed 9 months ago

celi commented 11 months ago

Hi,

It looks like FastExpressionCompiler is not comparing correctly nullable types. I didn't find any mention of it.

public static class FastExpressionCompilerTests
{
    public class Test
    {
        public decimal? D1 { get; set; }
    }

    public static void RunTest()
    {
        Expression<Func<Test, bool>> expression = t => t.D1 < 20;

        var normalCompiled = expression.Compile();

        var fastCompiled = expression.CompileFast(true, CompilerFlags.EnableDelegateDebugInfo);

        var test = new Test()
        {
            D1 = null
        };

        var result1 = normalCompiled(test); // false

        var result2 = fastCompiled(test); // true
    }
}

after execution result1 is equal false, but result2 is equal true

dadhi commented 9 months ago

@celi Missed this one, will look now. Thanks for posting.

dadhi commented 9 months ago

@celi Yep, reproduced :/ Will fix.