Skip to content

Commit

Permalink
already fixed #420
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Oct 13, 2024
1 parent 7272c31 commit 1d97907
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using NUnit.Framework;

#if LIGHT_EXPRESSION
using FastExpressionCompiler.LightExpression;
using static FastExpressionCompiler.LightExpression.Expression;
namespace FastExpressionCompiler.LightExpression.IssueTests;
#else
using static System.Linq.Expressions.Expression;
namespace FastExpressionCompiler.IssueTests;
#endif

[TestFixture]
public class Issue420_Nullable_DateTime_comparison_differs_from_Expression_Compile : ITest
{
public int Run()
{
Original_case();
return 1;
}

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

[Test]
public void Original_case()
{
var time = DateTime.UtcNow;

var p = new ParameterExpression[1]; // the parameter expressions
var e = new Expression[3]; // the unique expressions
var expr = Lambda<Func<HasDateTime, bool>>(
e[0] = MakeBinary(ExpressionType.Equal,
e[1] = Property(
p[0] = Parameter(typeof(HasDateTime), nameof(HasDateTime)),
typeof(HasDateTime).GetProperty(nameof(HasDateTime.T))),
e[2] = Constant(time, typeof(DateTime?)),
liftToNull: false,
typeof(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)
]);

expr.PrintCSharp();

var fs = expr.CompileSys();
fs.PrintIL();

var ff = expr.CompileFast(true, CompilerFlags.ThrowOnNotSupportedExpression);
ff.PrintIL();

var hasDT = new HasDateTime(time);
Assert.IsTrue(fs(hasDT));
Assert.IsTrue(ff(hasDT));
}
}
3 changes: 3 additions & 0 deletions test/FastExpressionCompiler.TestsRunner.Net472/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ void Run(Func<int> run, string name = null)
Run(new Issue419_The_JIT_compiler_encountered_invalid_IL_code_or_an_internal_limitation().Run);
Run(new LightExpression.IssueTests.Issue419_The_JIT_compiler_encountered_invalid_IL_code_or_an_internal_limitation().Run);

Run(new Issue420_Nullable_DateTime_comparison_differs_from_Expression_Compile().Run);
Run(new LightExpression.IssueTests.Issue420_Nullable_DateTime_comparison_differs_from_Expression_Compile().Run);

Run(new Issue421_Date_difference_is_giving_wrong_negative_value().Run);

Run(new Issue422_InvalidProgramException_when_having_TryCatch_Default_in_Catch().Run);
Expand Down
4 changes: 4 additions & 0 deletions test/FastExpressionCompiler.TestsRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Program
{
public static void Main()
{
// new LightExpression.IssueTests.Issue420_Nullable_DateTime_comparison_differs_from_Expression_Compile().Run();
// new LightExpression.IssueTests.Issue419_The_JIT_compiler_encountered_invalid_IL_code_or_an_internal_limitation().Run();
// new Issue421_Date_difference_is_giving_wrong_negative_value().Run();
// new ArithmeticOperationsTests().Run();
Expand Down Expand Up @@ -318,6 +319,9 @@ void Run(Func<int> run, string name = null)
Run(new Issue419_The_JIT_compiler_encountered_invalid_IL_code_or_an_internal_limitation().Run);
Run(new LightExpression.IssueTests.Issue419_The_JIT_compiler_encountered_invalid_IL_code_or_an_internal_limitation().Run);

Run(new Issue420_Nullable_DateTime_comparison_differs_from_Expression_Compile().Run);
Run(new LightExpression.IssueTests.Issue420_Nullable_DateTime_comparison_differs_from_Expression_Compile().Run);

Run(new Issue421_Date_difference_is_giving_wrong_negative_value().Run);

Run(new Issue422_InvalidProgramException_when_having_TryCatch_Default_in_Catch().Run);
Expand Down

0 comments on commit 1d97907

Please sign in to comment.