Skip to content

Commit 37ed8a5

Browse files
author
Maksim Volkau
committed
working on #480
1 parent 820e157 commit 37ed8a5

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7549,7 +7549,9 @@ private static void CollectCallingTestName()
75497549
/// In case of exception FEC will emit the whole computation to throw exception in the invocation phase</summary>
75507550
public static bool TryInterpretBool(out bool result, Expression expr, CompilerFlags flags)
75517551
{
7552-
Debug.Assert(expr.Type.IsPrimitive);
7552+
var exprType = expr.Type;
7553+
Debug.Assert(exprType.IsPrimitive || exprType.GetUnderlyingNullableTypeOrNull()?.IsPrimitive == true,
7554+
"Can reduce the boolean for the expressions of primitive types or for nullable of primitives but found " + expr.Type);
75537555
result = false;
75547556
if ((flags & CompilerFlags.DisableInterpreter) != 0)
75557557
return false;

src/FastExpressionCompiler/TestTools.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public static class TestTools
3838
static TestTools()
3939
{
4040
#if DEBUG
41-
// AllowPrintIL = true;
41+
AllowPrintIL = true;
4242
AllowPrintCS = true;
43-
// AllowPrintExpression = true;
43+
AllowPrintExpression = true;
4444
#endif
4545
}
4646

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
3+
#if LIGHT_EXPRESSION
4+
using FastExpressionCompiler.LightExpression.ImTools;
5+
using static FastExpressionCompiler.LightExpression.Expression;
6+
namespace FastExpressionCompiler.LightExpression.IssueTests;
7+
#else
8+
using System.Linq.Expressions;
9+
using static System.Linq.Expressions.Expression;
10+
namespace FastExpressionCompiler.IssueTests;
11+
#endif
12+
13+
public struct Issue480_CLR_detected_an_invalid_program_exception : ITestX
14+
{
15+
public void Run(TestRun t)
16+
{
17+
Original_case(t);
18+
}
19+
20+
public void Original_case(TestContext t)
21+
{
22+
var p1 = Condition(Equal(Constant(true), Constant(true)), Constant(null, typeof(bool?)), Constant(null, typeof(bool?)));
23+
var p2 = Condition(Equal(Constant(true), Constant(true)), Constant(null, typeof(bool?)), Constant(null, typeof(bool?)));
24+
var exp = Convert(OrElse(p1, p2), typeof(object));
25+
var expr = Lambda<Func<object>>(exp);
26+
27+
expr.PrintCSharp();
28+
29+
var fs = expr.CompileSys();
30+
fs.PrintIL(format: ILDecoder.ILFormat.AssertOpCodes);
31+
32+
// the compiled function should return default(int), yet it calls reader.GetInt32 instead
33+
var a = fs();
34+
35+
var ff = expr.CompileFast(false);
36+
ff.PrintIL(format: ILDecoder.ILFormat.AssertOpCodes);
37+
var b = ff();
38+
}
39+
}

test/FastExpressionCompiler.IssueTests/Issue490_Regression_in_compiling_lambdas_with_ref_struct_parameters.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace FastExpressionCompiler.LightExpression.IssueTests;
1010
#else
1111
using System.Linq.Expressions;
12-
using FastExpressionCompiler.ImTools;
1312
using static System.Linq.Expressions.Expression;
1413
namespace FastExpressionCompiler.IssueTests;
1514
#endif

test/FastExpressionCompiler.TestsRunner/Program.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ public static void Main()
1717

1818
// ILGeneratorTools.DisableILGeneratorPooling = true;
1919
// LightExpression.ILGeneratorTools.DisableILGeneratorPooling = true;
20-
21-
new Issue284_Invalid_Program_after_Coalesce().Run(); // test print cs
22-
new Issue440_Errors_with_simplified_Switch_cases().Run(); // test print cs
23-
20+
// new Issue284_Invalid_Program_after_Coalesce().Run(); // test print cs
21+
// new Issue440_Errors_with_simplified_Switch_cases().Run(); // test print cs
2422
// new LoopTests().Run(); // test print cs
2523
// new Issue458_Support_TryFault().Run();
2624
// new Issue127_Switch_is_supported().Run();
@@ -34,7 +32,10 @@ public static void Main()
3432
// new Issue461_InvalidProgramException_when_null_checking_type_by_ref().Run();
3533

3634

37-
var st = new TestRun();
35+
var st = new TestRun(TestFlags.RethrowException);
36+
37+
// st.Run(new Issue480_CLR_detected_an_invalid_program_exception());
38+
3839
#if NET8_0_OR_GREATER
3940
st.Run(new Issue487_Fix_ToCSharpString_output_for_boolean_equality_expressions());
4041
st.Run(new Issue475_Reuse_DynamicMethod_if_possible());

0 commit comments

Comments
 (0)