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

Nullable<DateTime> comparison differs from Expression.Compile #420

Closed
michaelgrosner opened this issue Jul 16, 2024 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@michaelgrosner
Copy link

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!

@dadhi dadhi self-assigned this Jul 18, 2024
@dadhi dadhi added the bug label Jul 18, 2024
@dadhi dadhi added this to the v4.2.2 milestone Jul 18, 2024
@dadhi
Copy link
Owner

dadhi commented Oct 12, 2024

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

@dadhi dadhi closed this as completed in 1d97907 Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants