Skip to content

Commit 75e314e

Browse files
committed
adding another test
1 parent e458d7d commit 75e314e

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

test/FastExpressionCompiler.IssueTests/Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_values.cs

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_v
1515
{
1616
public int Run()
1717
{
18+
More_simplified_test_no_inlining_for_SystemCompile_with_Execute_no_assigning();
19+
1820
More_simplified_test_no_inlining_for_SystemCompile_with_Execute();
1921
More_simplified_test_no_inlining();
2022
Simplified_test_no_inlining();
@@ -23,18 +25,60 @@ public int Run()
2325
Nested_lambda_with_shared_variable_Workaround_with_struct();
2426
Nested_lambda_with_shared_variable();
2527
Nested_lambda_with_shared_variable_Workaround();
26-
return 7;
28+
29+
return 8;
2730
}
2831

2932
public class TestClass
3033
{
31-
public static void Execute(Action action) => action();
34+
public static void ExecuteAction(Action action) => action();
35+
public static int ExecuteFunc(Func<int> func) => func();
36+
}
37+
38+
[Test]
39+
public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute_no_assigning()
40+
{
41+
var execute = typeof(TestClass).GetMethod(nameof(TestClass.ExecuteFunc));
42+
43+
var myVar = Variable(typeof(int), "myVar");
44+
var expr = Lambda<Func<int>>(
45+
Block(
46+
new[] { myVar },
47+
Assign(myVar, Constant(5)),
48+
Call(execute, Lambda<Func<int>>(Add(myVar, Constant(3)))),
49+
myVar
50+
)
51+
);
52+
53+
expr.PrintCSharp();
54+
// outputs:
55+
var @cs = (Func<int>)(() => //int
56+
{
57+
int myVar = default;
58+
myVar = 5;
59+
TestClass.ExecuteFunc((Func<int>)(() => //int
60+
myVar + 3));
61+
return myVar;
62+
});
63+
Assert.AreEqual(5, @cs());
64+
65+
var fs = expr.CompileSys();
66+
fs.PrintIL();
67+
68+
var sr = fs();
69+
Assert.AreEqual(5, sr);
70+
71+
var ff = expr.CompileFast(false);
72+
ff.PrintIL();
73+
74+
var fr = ff();
75+
Assert.AreEqual(5, fr);
3276
}
3377

3478
[Test]
3579
public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute()
3680
{
37-
var execute = typeof(TestClass).GetMethod(nameof(TestClass.Execute));
81+
var execute = typeof(TestClass).GetMethod(nameof(TestClass.ExecuteAction));
3882

3983
var myVar = Variable(typeof(int), "myVar");
4084
var expr = Lambda<Func<int>>(
@@ -53,7 +97,7 @@ public void More_simplified_test_no_inlining_for_SystemCompile_with_Execute()
5397
var sr = fs();
5498
Assert.AreEqual(3, sr);
5599

56-
var ff = expr.CompileFast(false, CompilerFlags.NoInvocationLambdaInlining);
100+
var ff = expr.CompileFast(false);
57101
ff.PrintIL();
58102

59103
var fr = ff();

test/FastExpressionCompiler.TestsRunner/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Program
1010
public static void Main()
1111
{
1212
new LightExpression.IssueTests.Issue437_Shared_variables_with_nested_lambdas_returning_incorrect_values().Run();
13-
new LightExpression.IssueTests.Issue353_NullReferenceException_when_calling_CompileFast_results().Run();
13+
// new LightExpression.IssueTests.Issue353_NullReferenceException_when_calling_CompileFast_results().Run();
1414
// new LightExpression.UnitTests.ArithmeticOperationsTests().Run();
1515

1616
RunAllTests();

0 commit comments

Comments
 (0)