From 6855540dd14a9c592e33094ec3ce80365506930b Mon Sep 17 00:00:00 2001 From: dadhi Date: Sun, 2 Oct 2022 23:12:21 +0200 Subject: [PATCH] 4th test for #347 without nullable --- ...returns_a_record_which_implements_IList.cs | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/test/FastExpressionCompiler.IssueTests/Issue347_InvalidProgramException_on_compiling_an_expression_that_returns_a_record_which_implements_IList.cs b/test/FastExpressionCompiler.IssueTests/Issue347_InvalidProgramException_on_compiling_an_expression_that_returns_a_record_which_implements_IList.cs index ddb87978..6cfdd75f 100644 --- a/test/FastExpressionCompiler.IssueTests/Issue347_InvalidProgramException_on_compiling_an_expression_that_returns_a_record_which_implements_IList.cs +++ b/test/FastExpressionCompiler.IssueTests/Issue347_InvalidProgramException_on_compiling_an_expression_that_returns_a_record_which_implements_IList.cs @@ -21,10 +21,41 @@ public class Issue347_InvalidProgramException_on_compiling_an_expression_that_re { public int Run() { - Test_nullable_param_in_closure_of_the_nested_lambda(); + Test_struct_parameter_in_closure_of_the_nested_lambda(); + // Test_nullable_param_in_closure_of_the_nested_lambda(); // Test_nullable_of_struct_and_struct_field_in_the_nested_lambda(); // Test_original(); - return 3; + return 4; + } + + [Test] + public void Test_struct_parameter_in_closure_of_the_nested_lambda() + { + var incMethod = GetType().GetMethod(nameof(Inc), BindingFlags.Public | BindingFlags.Static); + var propValue = typeof(NotifyModel).GetProperty(nameof(NotifyModel.Number1)); + + var p = Parameter(typeof(NotifyModel), "m"); + var expr = Lambda>( + Call(incMethod, Lambda>(Property(p, propValue))), + p + ); + + expr.PrintCSharp(); + + var fs = expr.CompileSys(); + fs.PrintIL(); + + var m = new NotifyModel(42, -1); + + var x = fs(m); + Assert.AreEqual(43, x); + + var f = expr.CompileFast(true, CompilerFlags.EnableDelegateDebugInfo); + Assert.IsNotNull(f); + f.PrintIL(); + + var y = f(m); + Assert.AreEqual(43, y); } [Test]