From 75e314e8ecd90dd68f5bfe8e21d2388d5a01827f Mon Sep 17 00:00:00 2001 From: dadhi Date: Sun, 22 Dec 2024 23:51:43 +0100 Subject: [PATCH] adding another test --- ...sted_lambdas_returning_incorrect_values.cs | 52 +++++++++++++++++-- .../Program.cs | 2 +- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/test/FastExpressionCompiler.IssueTests/Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_values.cs b/test/FastExpressionCompiler.IssueTests/Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_values.cs index bf8ee80b..f4d76755 100644 --- a/test/FastExpressionCompiler.IssueTests/Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_values.cs +++ b/test/FastExpressionCompiler.IssueTests/Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_values.cs @@ -15,6 +15,8 @@ public class Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_v { public int Run() { + More_simplified_test_no_inlining_for_SystemCompile_with_Execute_no_assigning(); + More_simplified_test_no_inlining_for_SystemCompile_with_Execute(); More_simplified_test_no_inlining(); Simplified_test_no_inlining(); @@ -23,18 +25,60 @@ public int Run() Nested_lambda_with_shared_variable_Workaround_with_struct(); Nested_lambda_with_shared_variable(); Nested_lambda_with_shared_variable_Workaround(); - return 7; + + return 8; } public class TestClass { - public static void Execute(Action action) => action(); + public static void ExecuteAction(Action action) => action(); + public static int ExecuteFunc(Func func) => func(); + } + + [Test] + public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute_no_assigning() + { + var execute = typeof(TestClass).GetMethod(nameof(TestClass.ExecuteFunc)); + + var myVar = Variable(typeof(int), "myVar"); + var expr = Lambda>( + Block( + new[] { myVar }, + Assign(myVar, Constant(5)), + Call(execute, Lambda>(Add(myVar, Constant(3)))), + myVar + ) + ); + + expr.PrintCSharp(); + // outputs: + var @cs = (Func)(() => //int + { + int myVar = default; + myVar = 5; + TestClass.ExecuteFunc((Func)(() => //int + myVar + 3)); + return myVar; + }); + Assert.AreEqual(5, @cs()); + + var fs = expr.CompileSys(); + fs.PrintIL(); + + var sr = fs(); + Assert.AreEqual(5, sr); + + var ff = expr.CompileFast(false); + ff.PrintIL(); + + var fr = ff(); + Assert.AreEqual(5, fr); } [Test] public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute() { - var execute = typeof(TestClass).GetMethod(nameof(TestClass.Execute)); + var execute = typeof(TestClass).GetMethod(nameof(TestClass.ExecuteAction)); var myVar = Variable(typeof(int), "myVar"); var expr = Lambda>( @@ -53,7 +97,7 @@ public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute() var sr = fs(); Assert.AreEqual(3, sr); - var ff = expr.CompileFast(false, CompilerFlags.NoInvocationLambdaInlining); + var ff = expr.CompileFast(false); ff.PrintIL(); var fr = ff(); diff --git a/test/FastExpressionCompiler.TestsRunner/Program.cs b/test/FastExpressionCompiler.TestsRunner/Program.cs index afe65a8e..78d76abf 100644 --- a/test/FastExpressionCompiler.TestsRunner/Program.cs +++ b/test/FastExpressionCompiler.TestsRunner/Program.cs @@ -10,7 +10,7 @@ public class Program public static void Main() { new LightExpression.IssueTests.Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_values().Run(); - new LightExpression.IssueTests.Issue353_NullReferenceException_when_calling_CompileFast_results().Run(); + // new LightExpression.IssueTests.Issue353_NullReferenceException_when_calling_CompileFast_results().Run(); // new LightExpression.UnitTests.ArithmeticOperationsTests().Run(); RunAllTests();