dadhi/FastExpressionCompiler

Nullable<DateTime> comparison differs from Expression.Compile

michaelgrosner opened this issue · 1 comments

Hello,

I came across an issue where I can't seem to explain why Expression.Compile works while FEC gives me a different answer. It's a pretty simple comparison, checking if the time passed in equals the time specified on a class with a nullable value.

public class HasDateTime(DateTime? t)
{
    public DateTime? T { get; } = t;
}

[Test]
public void DateTimeTest()
{
    var time = DateTime.UtcNow;
    
    var p = new ParameterExpression[1]; // the parameter expressions
    var e = new Expression[3]; // the unique expressions
    var exp = Expression.Lambda<Func<HasDateTime, bool>>(
        e[0]=Expression.MakeBinary(ExpressionType.Equal,
            e[1]=Expression.Property(
                p[0]=Expression.Parameter(typeof(HasDateTime), nameof(HasDateTime)),
                typeof(HasDateTime).GetProperty(nameof(HasDateTime.T))),
            e[2]=Expression.Constant(time, typeof(System.DateTime?)),
            liftToNull: false,
            typeof(System.DateTime).GetMethods().Single(x => !x.IsGenericMethod && x.Name == "op_Equality" && x.GetParameters().Select(y => y.ParameterType).SequenceEqual(new[] { typeof(System.DateTime), typeof(System.DateTime) }))),
        p[0 // (HasDateTime)
        ]);

    
    Assert.IsTrue(exp.Compile()(new HasDateTime(time)));     // passes, as expected.
    Assert.IsTrue(exp.CompileFast()(new HasDateTime(time))); // this fails!
}

Thanks!

@michaelgrosner Sorry for the late response, it is next in queue to look at.