Skip to content

Commit 715126e

Browse files
committed
added failing test for #308
1 parent f27141b commit 715126e

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using NUnit.Framework;
2+
using System;
3+
#if LIGHT_EXPRESSION
4+
using static FastExpressionCompiler.LightExpression.Expression;
5+
namespace FastExpressionCompiler.LightExpression.IssueTests
6+
#else
7+
using static System.Linq.Expressions.Expression;
8+
namespace FastExpressionCompiler.IssueTests
9+
#endif
10+
{
11+
[TestFixture]
12+
public class Issue308_Wrong_delegate_type_returned_with_closure : ITest
13+
{
14+
public int Run()
15+
{
16+
Test1();
17+
return 1;
18+
}
19+
20+
delegate string Command();
21+
22+
//[Test]
23+
public void Test1()
24+
{
25+
var p = Parameter(typeof(string), "vm");
26+
var expr = Lambda<Func<string, Command>>(Lambda<Command>(p), p);
27+
28+
expr.PrintCSharp();
29+
30+
var fSys = expr.CompileSys();
31+
fSys.PrintIL();
32+
33+
Assert.IsInstanceOf<Command>(fSys(null));
34+
35+
var fFast = expr.CompileFast();
36+
fFast.PrintIL();
37+
38+
Assert.IsInstanceOf<Command>(fFast(null));
39+
}
40+
}
41+
}

test/FastExpressionCompiler.TestsRunner/Program.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public static void Main()
1111
{
1212
RunAllTests();
1313

14+
//new FastExpressionCompiler.LightExpression.IssueTests.Issue308_Wrong_delegate_type_returned_with_closure().Run();
15+
1416
// new FastExpressionCompiler.LightExpression.IssueTests.Issue307_Switch_with_fall_through_throws_InvalidProgramException().Run();
1517
// new FastExpressionCompiler.LightExpression.IssueTests.Issue305_CompileFast_generates_incorrect_code_with_arrays_and_printing().Run();
1618
// new FastExpressionCompiler.LightExpression.IssueTests.Issue261_Loop_wih_conditions_fails().Run();
@@ -57,7 +59,7 @@ void Run(Func<int> run, string name = null)
5759
Console.WriteLine();
5860

5961
// todo: @perf try Parallel.ForEach
60-
var unitTests = Task.Run(() =>
62+
var unitTests = Task.Run(() =>
6163
{
6264
Run(new ArithmeticOperationsTests().Run);
6365
Run(new FastExpressionCompiler.LightExpression.UnitTests.ArithmeticOperationsTests().Run);
@@ -107,7 +109,7 @@ void Run(Func<int> run, string name = null)
107109

108110
});
109111

110-
var issueTests = Task.Run(() =>
112+
var issueTests = Task.Run(() =>
111113
{
112114
Run(new Issue14_String_constant_comparisons_fail().Run);
113115
Run(new FastExpressionCompiler.LightExpression.IssueTests.Issue14_String_constant_comparisons_fail().Run);
@@ -188,7 +190,7 @@ void Run(Func<int> run, string name = null)
188190

189191
Run(new Issue248_Calling_method_with_in_out_parameters_in_expression_lead_to_NullReferenceException_on_calling_site().Run);
190192
Run(new FastExpressionCompiler.LightExpression.IssueTests.Issue248_Calling_method_with_in_out_parameters_in_expression_lead_to_NullReferenceException_on_calling_site().Run);
191-
193+
192194
Run(new Issue251_Bad_code_gen_for_byRef_parameters().Run);
193195
Run(new FastExpressionCompiler.LightExpression.IssueTests.Issue251_Bad_code_gen_for_byRef_parameters().Run);
194196
#if NETCOREAPP3_1
@@ -212,14 +214,14 @@ void Run(Func<int> run, string name = null)
212214

213215
Run(new Issue300_Bad_label_content_in_ILGenerator_in_the_Mapster_benchmark_with_FEC_V3().Run);
214216
Run(new FastExpressionCompiler.LightExpression.IssueTests.Issue300_Bad_label_content_in_ILGenerator_in_the_Mapster_benchmark_with_FEC_V3().Run);
215-
217+
216218
Run(new Issue302_Error_compiling_expression_with_array_access().Run);
217219

218220
Run(new Issue305_CompileFast_generates_incorrect_code_with_arrays_and_printing().Run);
219221
Run(new FastExpressionCompiler.LightExpression.IssueTests.Issue305_CompileFast_generates_incorrect_code_with_arrays_and_printing().Run);
220222
Run(new Issue307_Switch_with_fall_through_throws_InvalidProgramException().Run);
221223
Run(new FastExpressionCompiler.LightExpression.IssueTests.Issue307_Switch_with_fall_through_throws_InvalidProgramException().Run);
222-
224+
223225
Console.WriteLine($"============={Environment.NewLine}IssueTests are passing in {sw.ElapsedMilliseconds} ms.");
224226
});
225227

0 commit comments

Comments
 (0)