Skip to content

Commit 3d059a4

Browse files
bluewingHuangbluewingHuang
authored andcommitted
add a fail test for Issue499
1 parent 344fa12 commit 3d059a4

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

test/FastExpressionCompiler.IssueTests/Issue499_InvalidProgramException_for_Sorting_and_comparison_function.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23

34
#if LIGHT_EXPRESSION
45
using FastExpressionCompiler.LightExpression.ImTools;
@@ -16,6 +17,7 @@ public void Run(TestRun t)
1617
{
1718
Quicksort_partition_with_nested_loops(t);
1819
Comparison_function_with_goto_labels(t);
20+
ArrayInList_ArrayAcceesError(t);
1921
}
2022

2123
// Reproduces the sorting use-case from https://github.com/dadhi/FastExpressionCompiler/issues/499
@@ -152,4 +154,44 @@ public void Comparison_function_with_goto_labels(TestContext t)
152154
t.AreEqual(-1, ff(3, 1));
153155
t.AreEqual(1, ff(1, 3));
154156
}
157+
158+
/// <summary>
159+
/// ff raise System.InvalidProgramException: Common Language Runtime detected an invalid program.
160+
/// </summary>
161+
/// <param name="t"></param>
162+
public void ArrayInList_ArrayAcceesError(TestContext t)
163+
{
164+
List<Expression> exps = new List<Expression>();
165+
var dataArrayList = Parameter(typeof(List<int?[]>), "dataArrayList");
166+
List<ParameterExpression> vars = new List<ParameterExpression>();
167+
var left_ListIndex = Parameter(typeof(int), "left_ListIndex");
168+
var left_ArrayIndex = Parameter(typeof(int), "left_ArrayIndex");
169+
170+
vars.AddRange(new ParameterExpression[] { left_ListIndex, left_ArrayIndex });
171+
var leftVars = new ParameterExpression[1];
172+
leftVars[0] = Parameter(typeof(int?), $"left_{0}");
173+
vars.Add(leftVars[0]);
174+
exps.Add(Assign(left_ListIndex, Constant(0)));
175+
exps.Add(Assign(left_ArrayIndex, Constant(0)));
176+
exps.Add(Assign(leftVars[0], ArrayAccess(Expression.Property(dataArrayList, "Item", left_ListIndex), left_ArrayIndex)));
177+
178+
BlockExpression block = Block(
179+
vars.ToArray(), exps
180+
);
181+
var expr = Lambda<Action<List<int?[]>>>(block, dataArrayList);
182+
expr.PrintCSharp();
183+
184+
List<int?[]> data1 = new List<int?[]> { new int?[] { 1 } };
185+
List<int?[]> data2 = new List<int?[]> { new int?[] { 1 } };
186+
187+
188+
var fs = expr.CompileSys();
189+
fs.PrintIL();
190+
fs(data1);
191+
192+
var ff = expr.CompileFast(ifFastFailedReturnNull: true);
193+
t.IsNotNull(ff);
194+
ff.PrintIL();
195+
ff(data2);
196+
}
155197
}

0 commit comments

Comments
 (0)